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

structured-binary-file

v1.0.1

Published

Reads and writes data records stored in fixed width binary. CircularFile adds 'fixed record count' files to the mix

Downloads

13

Readme

structured-binary-file

FixedRecordFile is a lightweight record manager that and writes binary data to fixed width record files. It provides an effecient storage mechanism similar to C's struct, yet keeps the convenience of working with Javascript objects.

CircularFile builds on FixedRecordFile but limits storage to a maximum number of records. Once that record limit has been reached, new appends drop the oldest record to make room for the newer record. This makes implementing things like rolling logs very simple.

Files composed of fixed width binary records have several advantages over text based storage. Records can be quickly retrieved based on a simple calculation. They are generally smaller than text based storage in that numbers are stored in their binary representation vs character sequences. Finally, field values are based on column position vs. some other type of data value delimeter being stored in the file.

Records in FixedRecordFile and its derivitives are defined using the binary encoder/decoder found in the project binary-parser-encoder.

Here is an example (complete examples can be found in the src/examples directory):

const FixedRecordFile = require("structured-binary-file").FixedRecordFile;
const Parser = require("binary-parser-encoder").Parser;

let PersonRecord = Parser.start()
                        .uint16("id")
                        .string("firstName", { length: 15, trim: true })
                        .string("lastName", { length: 25, trim: true })
                        .nest("address", { type: Parser.start()
                                                .uint32("number")
                                                .string("street", { length: 25, trim: true })
                                                .string("city", { length: 20, trim: true })
                                                .string("state", { length: 2, trim: true })
                                                .uint32("zip")
                                         });


var file = new FixedRecordFile(PersonRecord);

// Open the file...
file.open("data-fixed-example.dat");

let rec = {  id: 1, 
                firstName: "John",
                lastName: "Doe", 
                address:  {
                    number: 10321,
                    street: "Main St.",
                    city: "Everytown",
                    state: "DC",
                    zip: 20010
                }
            };

console.log(`Adding record as ${JSON.stringify(rec)}`);
file.appendRecord(rec);


// Retrieve and modify the above record...
rec = file.readRecord(0);
rec.firstName = "Jane";
rec.address.street = "Elm St.";
file.writeRecord(0, rec);


// Dump the contents of the file
console.log("\n\nFile contents:");
file.forEach(rec => { console.log(`    ${JSON.stringify(rec)}`) } );