https://github.com/afeiship/file-chunker
Efficiently chunk files and process them in parallel streams.
https://github.com/afeiship/file-chunker
blob chunk file html5 parallel
Last synced: 10 months ago
JSON representation
Efficiently chunk files and process them in parallel streams.
- Host: GitHub
- URL: https://github.com/afeiship/file-chunker
- Owner: afeiship
- License: mit
- Created: 2018-09-03T00:27:25.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-12-27T11:59:27.000Z (over 1 year ago)
- Last Synced: 2025-08-12T14:48:25.863Z (10 months ago)
- Topics: blob, chunk, file, html5, parallel
- Language: TypeScript
- Homepage: https://afeiship.github.io/file-chunker/
- Size: 39.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# file-chunker
> Efficiently chunk files and process them in parallel streams.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]
## installation
```shell
npm install @jswork/file-chunker
```
## usage
```js
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](https://github.com/afeiship/file-chunker/blob/master/LICENSE.txt).
[version-image]: https://img.shields.io/npm/v/@jswork/file-chunker
[version-url]: https://npmjs.org/package/@jswork/file-chunker
[license-image]: https://img.shields.io/npm/l/@jswork/file-chunker
[license-url]: https://github.com/afeiship/file-chunker/blob/master/LICENSE.txt
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/file-chunker
[size-url]: https://github.com/afeiship/file-chunker/blob/master/dist/file-chunker.min.js
[download-image]: https://img.shields.io/npm/dm/@jswork/file-chunker
[download-url]: https://www.npmjs.com/package/@jswork/file-chunker