Skip to content

clockwork-dog/imohash

Repository files navigation

imohash for JavaScript & TypeScript

imohash is a fast, constant-time hashing library for JavaScript & TypeScript. It uses file size and sampling to calculate hashes quickly, regardless of file size.

It was originally released as a Go library.

Installation

npm install imohash

or

yarn add imohash

Usage

import { hashFile } from "imohash";

const hash = await hashFile("/tmp/path/to/file");
const hashInHex = hash.toString("hex");

Uses

Because imohash only reads a small portion of a file's data, it is very fast and well suited to file synchronization and deduplication, especially over a fairly slow network. A need to manage media (photos and video) over Wi-Fi between a NAS and multiple family computers is how the library was born.

If you just need to check whether two files are the same, and understand the limitations that sampling imposes (see below), imohash may be a good fit.

Misuses

Because imohash only reads a small portion of a file's data, it is not suitable for:

  • file verification or integrity monitoring
  • cases where fixed-size files are manipulated
  • anything cryptographic

Design

The algorithm is described in the original repository.

Development

You can run type checking, linting, and tests with these commands:

yarn run types
yarn run lint
yarn run test

Building the library for release can be done with:

yarn run build

You can also run the bundler in watch mode with:

yarn run watch

Alternative implementations

License

MIT

About

A Javascript implementation of imohash

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •