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

binary-data-chunking

v3.0.1

Published

A small library that simplifies sending large amounts of chunked binary data

Downloads

333

Readme

binary-data-chunking

A simple binary data chunking library that simplifies sending large amounts of chunked binary data. For example via. the WebRTC DataChannel.

This is useful in the case that you would like to received chunks of data instead of one large file Blob at the end of the transfer (as in Firefox), and avoid the issues with sending large files in Chrome.

Although this was designed for use in WebRTC, it could be used in other environments where you need a custom way to send chunks binary of information.

Environment

This can be used both in a node.js or browser environment (targeted browsers are the latest: Chrome, Firefox and eventually Edge)

Usage

Include

Node

var BDC = require('binary-data-chunking');

Browser

Include the either the minified, or non-minified files in the dist/ directory.

dist/binary-data-chunking.js
dist/binary-data-chunking.min.js

Initialize

You create a new BDC instance for each file you wish to transfer. The initialization parameters give the basic information about your file.

Sending client

var file = new BDC({ 
    name: 'sample.mp4',
    mimeType: 'video/mp4',
    arrayBuffer: ab, // must be in the ArrayBuffer format
    chunkSize: 16000 // chunkSize to use *before* meta-data additions.
});

file.fileSize;   // returns actual file size based on ArrayBuffer
file.totalChunks; // total number of chunks that will be sent (based on file size and chunk size)
file.checksum;   // checksum based on ArrayBuffer

file.getMetadata();  // to be sent to other end to initialize the transfer, used to initialize a BDC instance on the receiving end.

file.clearData();    // removes arrayBuffer data and all stored information

var to = file.getTransferObject(); // unique instance to track the transfering of each chunk 

to.getChunk([pos]); // will get next chunk, or optionally get the chunk based on the number (position) specific. 
                    // note, the chunk will have header info embedded in the first few bytes, to receiving client 
                    // must also have an instance created based on the information returned from `file.getMetadata()`
to.currentIndex;    // returns the current number if chunks given from `getChunk()`
                      

Receiving client

When you receive the metadata sent from the sending client, you can initialize a new BDC instance

// when metadata is received
var file = new BDC(metadata);

file.onChunkReceived(function (ab, pos) {
    // this handler will be called when a chunk that relates to this file instance is received    
});

file.onComplete(function (ab, metadata) {
   // here you receive the completed ArrayBuffer object along with it's metadata 
});

var to = file.getTransferObject();
var payload = to.getUnpackedChunk(); // next ordered arrayBuffer without the binary metadata bits

// when a binary chunk is received, we don't know yet which file object it belongs to, so we submit it to the Factory object and wait for the handler to be called
BDC.submitChunk(chunk);

file.generatedChecksum; // contains then generated checksum once a transfer is complete

With your file object instance, you can access the methods like totalChunks, fileSize, getMetadata(), getChunk() and once completed getFile().

Known Issues

The generation of a uid does have some collision potential, we we are limited in space, and also we do not know what uids have already been generated on the receiving end(s) of the file transfer(s).