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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnet/checksum

v0.1.10

Published

A simple utility to calculate the checksum of a file, directory or content

Downloads

190

Readme

@fnet/checksum

This project offers a straightforward tool for generating checksums, which are useful for verifying the integrity of files, directories, or data structures. It provides a reliable method to ensure that the contents of your data remain consistent and unchanged during transfer or storage.

How It Works

The tool computes a checksum, a form of a digital fingerprint, using a specified hashing algorithm (defaulted to SHA-256) for various types of inputs. Whether you want to validate the integrity of a single file, a whole directory, or even a complex object structure, this utility offers a simple and effective way to calculate these checksums.

Key Features

  • File Checksum: Compute the checksum of a single file to ensure its integrity.
  • Directory Checksum: Calculate a checksum for all files within a directory, maintaining an alphabetical order for consistency.
  • Object and Array Checksum: Supports generating checksums for strings, buffers, nested objects, and arrays, giving flexible support for various data structures.

Conclusion

In summary, @fnet/checksum provides a dependable way to compute checksums for files, directories, and various data structures. It aids users in confirming the data integrity in a straightforward and efficient manner.

Developer Guide for @fnet/checksum Library

Overview

The @fnet/checksum library is designed to help developers compute checksums for various types of data, ensuring data integrity and reliability. It provides functions to generate checksums for files, directories, and data objects using configurable hashing algorithms. This can be particularly useful for verifying data consistency during file transfers, backups, or data storage.

Installation

To add @fnet/checksum to your project, use either npm or yarn:

npm install @fnet/checksum

or

yarn add @fnet/checksum

Usage

The library exports a core function that allows you to compute checksums. Here's how you can use it in different scenarios:

import calculateChecksum from '@fnet/checksum';

// Example: Calculate checksum for a string or Buffer content
calculateChecksum({ content: 'Sample data' }).then(checksum => {
  console.log(checksum);
});

// Example: Calculate checksum for files
calculateChecksum({ path: '/path/to/file.txt' }).then(checksum => {
  console.log(checksum);
});

// Example: Calculate checksum for directories
calculateChecksum({ path: '/path/to/directory' }).then(checksum => {
  console.log(checksum);
});

// Example: Calculate checksum for an object
calculateChecksum({ content: { 'file1': 'data1', 'file2': 'data2' } }).then(checksum => {
  console.log(checksum);
});

Examples

Calculate Checksum for Simple Text

calculateChecksum({ content: 'Hello World' }).then(checksum => {
  console.log('Checksum for text:', checksum.value);
});

Calculate Checksum for a File

calculateChecksum({ path: '/path/to/myfile.txt' }).then(checksum => {
  console.log('Checksum for file:', checksum.value);
});

Calculate Checksum for a Directory

calculateChecksum({ path: '/path/to/mydir' }).then(checksum => {
  console.log('Checksum for directory:', checksum.value);
  console.log('Files included in checksum:', checksum.inputs);
});

Calculate Checksum for an Object

const dataObject = {
  'file1.txt': 'This is content of file1',
  'file2.txt': 'This is content of file2'
};

calculateChecksum({ content: dataObject }).then(checksum => {
  console.log('Checksum for object:', checksum.value);
});

Acknowledgement

The @fnet/checksum library utilizes Node.js built-in modules for filesystem operations and cryptographic processes. Special thanks to contributors and the open-source community for making such tools accessible and reliable.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  content:
    oneOf:
      - type: string
      - type: array
        items:
          type: string
      - type: object
        additionalProperties:
          oneOf:
            - type: string
            - type: object
              additionalProperties:
                type:
                  - string
                  - object
            - type: array
              items:
                type: string
        propertyNames:
          type: string
    description: The content to calculate checksum for. Can be string, Buffer (as
      string), or an object with nested values.
  path:
    type: string
    description: The file or directory path to calculate checksum from.
  algorithm:
    type: string
    default: sha256
    description: The hashing algorithm to use.
required: []
additionalProperties: false