# file-type - Buffer안의 파일 타입 알아내기

> Clean Markdown view of GeekNews topic #2748. Use the original source for factual precision when an external source URL is present.

## Metadata

- GeekNews HTML: [https://news.hada.io/topic?id=2748](https://news.hada.io/topic?id=2748)
- GeekNews Markdown: [https://news.hada.io/topic/2748.md](https://news.hada.io/topic/2748.md)
- Type: news
- Author: [xguru](https://news.hada.io/@xguru)
- Published: 2020-08-31T09:56:29+09:00
- Updated: 2020-08-31T09:56:29+09:00
- Original source: [github.com](https://github.com/sindresorhus/file-type)
- Points: 7
- Comments: 0

## Topic Body

- 매직넘버*로 파일타입을 감지, Promise를 리턴하는 JS라이브러리

ㅤ→ .fromBuffer : Buffer/Uint8Array/ArrayBuffer

ㅤ→ .fromFile : 경로명

ㅤ→ .fromStream : Node.js 스트림

ㅤ→ .fromTokenizer : ITokenizer - @tokenizer/http , @tokenizer/s3 등으로 원격 파일 체크

- 약 120여종의 파일타입 지원

ㅤ→ jpg/png/gif/webp/tif/bmp/ico/psd/ai/skp/avif

ㅤ→ zip/tar/rar/gz/7z/dmg/lzh

ㅤ→ mp4/mkv/webm/mov/avi/wmv

ㅤ→ mp3/ogg/flac/wav/wma/ac3

ㅤ→ pdf/epub/mobi/ps/eps

ㅤ→ exe/swf/flv

ㅤ→ rtf/docx/pptx/xlsx/odt/ods/odp

ㅤ→ ttf/otf/woff/woff2

ㅤ→ ics

ㅤ→ pcap

* 매직넘버 : 파일을 구분하기 위해 파일 앞부분에 넣어두는 특정 값들. 초기 유닉스에서는 2바이트 정도만 쓰였으나 요즘은 앞부분 여러개의 바이트를 사용하기도

ㅤ→ 자바 .class 파일은 "CAFEBABE" 로 시작

ㅤ→ GIF89a 는 ASCII코드 "GIF89a"로 시작 : 47 49 46 38 39 61

ㅤ→ JPEG 은 "FF D8" 로 시작해서 "FF D9"로 끝남

ㅤ→ 유닉스/리눅스 스크립트 파일은 "#!"

ㅤ→ PDF 파일은 "%PDF"

ㅤ→ ZIP 파일은 "PK"로 시작 - 도스용 PKZIP 개발자 Phil Katz를 따서

## Comments



_No public comments on this page._
