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

large-split

v0.1.2

Published

A collection of methods that split large Buffers and files.

Downloads

25

Readme

(a histogram of downloads)

This module (large-split) is a collection of methods that split large Buffers and files.

It is inspired by Ryan Day's buffer-split module, but has the following differences:

  • does not have dependencies,

  • requires Node.js version 4.x (or newer) to run,

  • has additional methods to process larger data structures.

Installing the splitter

(npm package version)

  • Latest packaged version: npm install large-split

  • Latest githubbed version: npm install https://github.com/Mithgol/node-large-split/tarball/master

You may visit https://github.com/Mithgol/node-large-split#readme occasionally to read the latest README because the package's version is not planned to grow after changes when they happen in README only. (And npm publish --force is forbidden nowadays.)

Using the splitter

When you require() the installed module, you get an object with the following methods:

bsplit(buf, splitBuf, includeDelim)

This method's name (bsplit) means “a Buffer's splitter”.

This method is directly inspired by Ryan Day's buffer-split module.

This method takes a large Buffer (buf) and splits it into an array of Buffers by separating the Buffer into subbuffers. That array is returned.

The second parameter (splitBuf) is used as a delimiter to decide where the next subbuffer starts.

If the third parameter (includeDelim) is present and true, then delimiters are included to the subbuffers that precede them.

Example:

var contentArray = require('large-split').bsplit(
   sourceBuffer,
   Buffer('\r\n') // CRLF
);

**Note: ** if a Buffer is large enough (hundreds of megabytes), it cannot be created (Node.js issue 3543). Use one of the following methods to split such data structures as files (without attempting to read the whole file to memory).

fsplit(filePath, splitBuf, includeDelim)

This method's name (fsplit) means “a file's splitter”.

This method takes a large file (using the given filePath) and splits it into an array of Buffers by separating the file's contents into subbuffers. That array is returned.

The second parameter (splitBuf) is used as a delimiter to decide where the next subbuffer starts.

If the third parameter (includeDelim) is present and true, then delimiters are included to the subbuffers that precede them.

The file is read synchronously in relatively small portions (50 megabytes each).

Example:

var contentArray = require('large-split').fsplit(
   sourceFilePath,
   Buffer('\r\n') // CRLF
);

**Note: ** if a file is large enough (a gigabyte or more), even an array of its subbuffers won't fit into memory (unless V8 options are changed). Use the following method to process each subbuffer separately.

isplit(filePath, splitBuf, iterator, includeDelim)

This method's name (isplit) means “an iterative splitter”.

This method takes a large file (using the given filePath) and splits it by separating the file's contents into subbuffers.

The second parameter (splitBuf) is used as a delimiter to decide where the next subbuffer starts.

If the fourth parameter (includeDelim) is present and true, then delimiters are included to the subbuffers that precede them.

The file is read synchronously in relatively small portions (50 megabytes each).

For each of the subbuffers (in order of appearance) the call iterator(nextBuf, bufIndex, last) is performed with the following parameters:

  • nextBuf — the next subbuffer,

  • bufIndex — the (zero-based) index of the subbuffer,

  • last — present and true if the given subbuffer is the last in the file.

Example:

isplit(
   sourcePath, Buffer('\r\n'), // CRLF
   (nextLineBuf, IDX, lastLine) => {
      if( nextLineBuf.length === 0 ){
         if( lastLine ){
            require('ciel').skip(
               `The file ${sourcePath} ends with an empty line.`
            );
            return;
         }
         require('ciel').fail(
            `The file ${sourcePath} contains an empty line. ` +
            "That's not the last line!"
         );
         return;
      }
      // ... more processing ...
   }
);

Testing the splitter

(build testing status)

It is necessary to install JSHint for testing.

  • You may install JSHint globally (npm install jshint -g) or locally (npm install jshint in the directory of the splitter).

After that you may run npm test (in the directory of the splitter). Only the JS code errors are caught; the code's behaviour is not tested.

License

MIT license (see the LICENSE file).