A Node.js library that determines if a filename or buffer is text or binary using smarter detection than other solutions.
Is Text or Binary? is a Node.js library that determines whether a filename or data buffer contains text or binary content. It solves the problem of accurately identifying file types by combining extension-based detection with intelligent buffer sampling, outperforming simpler solutions that rely on single-point checks.
Node.js developers building tools that process files, such as static site generators, build systems, or file management utilities, where accurate text/binary differentiation is critical.
Developers choose this library for its proven accuracy and performance, using a hybrid detection method that avoids common pitfalls like misclassifying UTF-16 files. It has been battle-tested in production since 2012, notably in DocPad and its dependents.
Determine if a filename and/or buffer is text or binary. Smarter detection than the other solutions.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Combines filename extension checks with multi-point buffer sampling, ensuring reliable detection even for tricky cases like UTF-16 files where content alone is insufficient, as highlighted in the README's philosophy.
Uses 24-byte samples from start, middle, and end of buffers, which is faster than full scans and more accurate than single-location checks, offering superior performance as documented.
Published as editions compatible with Node.js, Deno, browsers, and TypeScript, making it adaptable across different JavaScript runtimes without major changes.
Has been in production since 2012, powering tools like DocPad, which attests to its robustness and accuracy in real-world scenarios per the README history.
Relies on separate packages for text and binary extensions, which may become outdated or incomplete, requiring manual updates or overrides for new file types.
Only distinguishes between UTF-8 and binary via getEncoding, lacking support for other encodings like UTF-16BE/LE or ASCII, which limits comprehensive file handling.
Offers multiple editions for different environments, which can be confusing for developers to choose the right one, adding unnecessary setup complexity.