1.0.9 • Published 1 year ago

@jswork/file-chunker v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago