🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

shardjs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shardjs

A tiny NPM package for splitting and recombining data.

1.1.2
latest
Source
npm
Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

GitHub package.json version npm GitHub package.json version

About

A tiny NPM package for splitting and recombining data.

Installation

npm i shardjs

Usage

Importing

import { shardify, blobify } from 'shardjs'

There are two methods in this package to split and recombine data.

Splitting

function shardify(blob, chunk, sizeMode = "MODE_BITSIZE", contentType = "text/plain")

Combining

function blobify(shards, contentType = "text/plain")

Examples

To split a data blob of plaintext into three equal parts.

If there is an additional data that cannot be divided equally, it will be added as a 4th item.

import { shardify } from 'shardjs'

const file = new File(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], 'example.txt')

var shards = shardify(file, 3, "MODE_DIVIDE", "text/plain")

To split a data blob of plaintext into N parts, where each part is 5000 bits.

import { shardify } from 'shardjs'

const file = new File(['0'.repeat(1000000)], 'example.txt')

var shards = shardify(file, 5000, "MODE_BITSIZE", "text/plain")

To recombine blobs of split plaintext data.

import { blobify } from 'shardjs'

const file = new File(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], 'example.txt')
var shards = shardify(file, 3, "MODE_DIVIDE", "text/plain")

var blob = blobify(shards, "text/plain")

Keywords

split

FAQs

Package last updated on 12 Jul 2022

Did you know?

Socket

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.

Install

Related posts