Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
binary-data-chunking
Advanced tools
A small library that simplifies sending large amounts of chunked binary data
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.
This can be used both in a node.js
or browser environment (targeted browsers are the latest: Chrome, Firefox and eventually Edge)
var BDC = require('binary-data-chunking');
Include the either the minified, or non-minified files in the dist/
directory.
dist/binary-data-chunking.js
dist/binary-data-chunking.min.js
You create a new BDC
instance for each file you wish to transfer. The initialization parameters give the basic information about your file.
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()`
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()
.
The generation of a uid
does have some collision potential, we we are limited in space, and also we do not know what uid
s have already been generated on the receiving end(s) of the file transfer(s).
FAQs
A small library that simplifies sending large amounts of chunked binary data
The npm package binary-data-chunking receives a total of 73 weekly downloads. As such, binary-data-chunking popularity was classified as not popular.
We found that binary-data-chunking demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.