js-split-file
v2.2.1
Published
A library to split big file to small binary data for nodejs and browsers.
Downloads
34
Readme
js-split-file
A library to split big file to small binary data for nodejs and browsers.
install
npm i js-split-file
usage
import SplitFile from "js-split-file";
// <script src="js-split-file/js-split-file.min.js"></script>
// react-native:
import SplitFile from "js-split-file/react-native";
const splitFile = new SplitFile();
const binary = new Uint8Array([1, 2, 3]); // for browser, from File or Blob to Uint8Array; for nodejs, from Buffer to Uint8Array
const blocks = splitFile.split(binary, "a.pdf");
const piece = splitFile.decodeBlock(blocks[0]);
options
const blocks = splitFile.split(new Uint8Array([1, 2, 3]), "a.pdf", 10000); // each piece's size <= 10000B
dependencies
- Uint8Array, or polyfill like
core-js
- for browser, it need
TextEncoder
andTextDecoder
, if the browsers don't support them, use polyfill liketext-encoding
change logs
// v2
import SplitFile from "js-split-file/nodejs";
import SplitFile from "js-split-file/browser";
// v1
import { SplitFile } from "js-split-file/nodejs";
import { SplitFile } from "js-split-file/browser";