npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@laurence-trippen/whatfile

v0.1.2

Published

Detects file types by bytes signatures.

Downloads

42

Readme

whatfile

A small Node.js library for detecting file types by their byte signatures (magic bytes). Instead of loading a whole file into memory, whatfile opens the file and reads only the few bytes it needs from disk.

This is useful when you deal with large files, untrusted uploads, or simply want a quick, dependency-free way to verify that a file really is what its extension claims to be.

Installation

npm install whatfile

npm link

Requires Node.js 22 (see .nvmrc).

Usage

The library is organized one module per format, exposed under a namespaced key. Currently only PDF is implemented.

const { PDF } = require("whatfile")

async function main() {
  const isPdf = await PDF.isPdf("./report.pdf")
  console.log(isPdf) // true

  const isEncrypted = await PDF.hasPdfPassword("./report.pdf")
  console.log(isEncrypted) // true if the PDF is password protected
}

main()

API

PDF.isPdf(path)

Reads the file header and checks for the %PDF- signature.

  • path string — path to the file on disk.
  • Returns Promise<boolean>true if the file starts with a valid PDF header, otherwise false.

Detection failures (missing file, permission errors, …) resolve to false rather than throwing, so the function is safe to call without a try/catch.

PDF.hasPdfPassword(path)

Checks whether a PDF is password protected by scanning the tail of the file for an /Encrypt entry. Only the last few kilobytes are read, so this works on large files too.

  • path string — path to the file on disk.
  • Returns Promise<boolean>true if the file is a PDF and appears to be encrypted, otherwise false. Returns false for non-PDF files.

How it works

Each detection function opens the file with fs/promises, reads only the bytes it needs into a pre-allocated buffer, and always closes the file handle afterwards. Two access patterns are used:

  • Header read — read a small fixed-size chunk from the start of the file and compare it against a known magic-byte constant.
  • Tail readstat() the file, then read only the last chunk to look for indicator bytes (for example /Encrypt). This avoids loading large files entirely.

TypeScript

Type declarations ship with the package, so no separate @types install is needed.

Roadmap

Additional formats are planned and will follow the same one-module-per-format pattern.

License

MIT © Laurence Louis Trippen