{"name":"isbinaryfile","version":"5.0.7","keywords":["text","binary","encoding","istext","is text","isbinary","is binary","is text or binary","is text or binary file","isbinaryfile","is binary file","istextfile","is text file"],"license":"MIT","_id":"isbinaryfile@5.0.7","maintainers":[{"name":"gjtorikian","email":"gjtorikian@gmail.com"}],"homepage":"https://github.com/gjtorikian/isBinaryFile#readme","bugs":{"url":"https://github.com/gjtorikian/isBinaryFile/issues"},"dist":{"shasum":"19a73f2281b7368dca9d3b3ac8a0434074670979","tarball":"http://registry-npm.ywwl.com/isbinaryfile/download/isbinaryfile-5.0.7.tgz","fileCount":5,"integrity":"sha512-gnWD14Jh3FzS3CPhF0AxNOJ8CxqeblPTADzI38r0wt8ZyQl5edpy75myt08EG2oKvpyiqSqsx+Wkz9vtkbTqYQ==","signatures":[{"sig":"MEYCIQDW2nqywL0yELmImV/PC2XLIap6HKrWKBe2nkADMdKr6AIhALh0SlRKEBNtD+oBXnDoZlPKEiTBNNt9kbuD8MpdfS/C","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12868,"size":4330,"noattachment":false,"key":"/isbinaryfile/-/isbinaryfile-5.0.7.tgz"},"main":"lib/index.js","types":"lib/index.d.ts","engines":{"node":">= 18.0.0"},"funding":"https://github.com/sponsors/gjtorikian/","gitHead":"a9d483b94d1d3bffd85f3ace95ddcf183d774976","scripts":{"lint":"tslint -p tsconfig.json","test":"jest --config jestconfig.json","build":"tsc","watch":"tsc -w","format":"prettier --write \"src/**/*.ts\" \"src/**/*.js\" && tslint --fix -c tslint.json 'src/**/*.ts'","prepare":"npm run build","release":"release-it","version":"npm run format && git add -A src","preversion":"npm run lint","postversion":"git push && git push --tags","prepublishOnly":"npm test && npm run lint"},"_npmUser":{"name":"gjtorikian","email":"gjtorikian@gmail.com"},"repository":{"url":"git+https://github.com/gjtorikian/isBinaryFile.git","type":"git"},"_npmVersion":"10.9.0","description":"Detects if a file is binary in Node.js. Similar to Perl's -B.","directories":{},"_nodeVersion":"22.11.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","tslint":"^5.20.1","ts-jest":"^29.1.4","prettier":"^1.19.1","release-it":"^19.0.4","typescript":"^4.9.4","@types/jest":"^23.3.14","@types/node":"^10.17.60","tslint-config-prettier":"^1.18.0"},"_npmOperationalInternal":{"tmp":"tmp/isbinaryfile_5.0.7_1762894813250_0.7595124998774405","host":"s3://npm-registry-packages-npm-production"},"readme":"# isBinaryFile\n\nDetects if a file is binary in Node.js. Similar to [Perl's `-B` switch](http://stackoverflow.com/questions/899206/how-does-perl-know-a-file-is-binary), in that:\n\n- it reads the first few thousand bytes of a file\n- checks for a `null` byte; if it's found, it's binary\n- flags non-ASCII characters. After a certain number of \"weird\" characters, the file is flagged as binary\n\nMuch of the logic is pretty much ported from [ag](https://github.com/ggreer/the_silver_searcher).\n\nNote: if the file doesn't exist or is a directory, an error is thrown.\n\n## Installation\n\n```\nnpm install isbinaryfile\n```\n\n## Usage\n\nReturns `Promise<boolean>` (or just `boolean` for `*Sync`). `true` if the file is binary, `false` otherwise.\n\n### isBinaryFile(filepath[, options])\n\n- `filepath` - a `string` indicating the path to the file.\n- `options` - an optional object with the following properties:\n  - `encoding` - an encoding hint (see [Encoding Hints](#encoding-hints) below)\n\n### isBinaryFile(bytes[, options])\n\n- `bytes` - a `Buffer` of the file's contents.\n- `options` - an optional object with the following properties:\n  - `size` - the size of the buffer (defaults to `bytes.length`)\n  - `encoding` - an encoding hint (see [Encoding Hints](#encoding-hints) below)\n\n### isBinaryFileSync(filepath[, options])\n\nSynchronous version of `isBinaryFile`.\n\n### isBinaryFileSync(bytes[, options])\n\nSynchronous version of `isBinaryFile` for buffers.\n\n### Examples\n\nHere's an arbitrary usage:\n\n```javascript\nimport { isBinaryFile, isBinaryFileSync } from 'isbinaryfile';\nimport fs from 'fs';\n\nconst filename = 'fixtures/pdf.pdf';\n\n// Async with file path\nconst result = await isBinaryFile(filename);\nif (result) {\n  console.log('It is binary!');\n} else {\n  console.log('No it is not.');\n}\n\n// Sync with buffer\nconst bytes = fs.readFileSync(filename);\nconsole.log(isBinaryFileSync(bytes)); // true or false\n\n// With explicit size option\nconst partialBuffer = Buffer.alloc(100);\nfs.readSync(fs.openSync(filename, 'r'), partialBuffer, 0, 100, 0);\nconsole.log(isBinaryFileSync(partialBuffer, { size: 100 }));\n```\n\n### Encoding Hints\n\nFor files that use non-UTF-8 encodings, you can provide encoding hints to improve detection accuracy:\n\n```javascript\nimport { isBinaryFile, isBinaryFileSync } from 'isbinaryfile';\n\n// UTF-16 files without BOM are auto-detected in most cases\nconst result1 = await isBinaryFile('utf16-file.txt');\n\n// Or provide explicit encoding hint\nconst result2 = await isBinaryFile('utf16-file.txt', { encoding: 'utf-16' });\n\n// ISO-8859-1 / Latin-1 encoded files\nconst result3 = isBinaryFileSync('german-text.txt', { encoding: 'latin1' });\n\n// CJK encoded files (Big5, GB2312, EUC-KR, etc.)\nconst result4 = isBinaryFileSync('chinese-big5.txt', { encoding: 'big5' });\nconst result5 = isBinaryFileSync('korean-text.txt', { encoding: 'euc-kr' });\n\n// Generic CJK hint when exact encoding is unknown\nconst result6 = isBinaryFileSync('asian-text.txt', { encoding: 'cjk' });\n```\n\n#### Supported Encoding Hints\n\n| Hint         | Description                                |\n| ------------ | ------------------------------------------ |\n| `utf-16`     | UTF-16 (auto-detect endianness)            |\n| `utf-16le`   | UTF-16 Little Endian                       |\n| `utf-16be`   | UTF-16 Big Endian                          |\n| `latin1`     | ISO-8859-1 / Latin-1                       |\n| `iso-8859-1` | Alias for latin1                           |\n| `cjk`        | Generic CJK (use when encoding is unknown) |\n| `big5`       | Traditional Chinese                        |\n| `gb2312`     | Simplified Chinese                         |\n| `gbk`        | Extended GB2312                            |\n| `euc-kr`     | Korean                                     |\n| `shift-jis`  | Japanese                                   |\n\n**Note:** UTF-16 without BOM is automatically detected in most cases without needing a hint.\n\n## Testing\n\nRun `npm test`.\n","publish_time":1762894813436,"_cnpm_publish_time":1762894813436,"dist-tags":{"latest":"6.0.0"}}