1.0.9 • Published 11 months ago

@jswork/file-chunker v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

file-chunker

Efficiently chunk files and process them in parallel streams.

version license size download

installation

npm install @jswork/file-chunker

usage

import FileChunk from '@jswork/file-chunker';

const ipt1 = document.getElementById('file');
const apiPut = ({ chunk }) => {
  return fetch('https://httpbin.org/post', {
    method: 'POST',
    body: chunk,
    headers: {
      'Content-Type': 'application/octet-stream'
    }
  }).then(r => r.json());
};

ipt1.addEventListener('change', function(e) {
  const files = e.target.files;
  if (files.length) {
    const file = files[0];
    const chunker = new FileChunk(file, {
      chunkSize: 1024 * 1024,
      concurrency: 3
    });
    console.log(chunker.chunkCount);
    chunker.processChunks(({ chunk, current, count }) => {
      console.log('chunk:', chunk, 'current:', current, 'count:', count, 'percent: ', (current / count * 100).toFixed(2) + '%');
      return apiPut({ chunk });
    }).then(res => {
      console.log('res: ', res);
    });
  }
});

license

Code released under the MIT license.

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago