Download client/src/FileChunker.js from linuxrun/deer: direct link, hf CLI and curl.
- Browser
- Download file 932 Bytes
-
https://huggingface.co/spaces/linuxrun/deer/resolve/ba89fcbd4ce8c877fd4fcffd6ecd14cddf11e110/client/src/FileChunker.js
- Command line
-
hf download hf://spaces/linuxrun/deer@ba89fcbd4ce8c877fd4fcffd6ecd14cddf11e110/client/src/FileChunker.js
-
curl -L -o FileChunker.js https://huggingface.co/spaces/linuxrun/deer/resolve/ba89fcbd4ce8c877fd4fcffd6ecd14cddf11e110/client/src/FileChunker.js
932 Bytes
| const CHUNK_SIZE = 64 * 1024; | |
| class FileChunker { | |
| constructor(file) { | |
| this.file = file; | |
| this.reader = new FileReader(); | |
| this.offset = 0; | |
| } | |
| getNextChunk() { | |
| return new Promise((resolve, reject) => { | |
| if (this.offset >= this.file.size) { | |
| resolve({ | |
| done: true, | |
| }); | |
| } | |
| this.reader.onload = (e) => { | |
| const chunk = e.target.result; | |
| this.offset += chunk.byteLength; | |
| resolve({ | |
| done: this.offset >= this.file.size, | |
| chunk, | |
| offset: this.offset, | |
| }); | |
| }; | |
| this.reader.onabort = () => { | |
| reject(new Error('FileReader abort')); | |
| }; | |
| this.reader.onerror = (evt) => { | |
| reject(new Error('FileReader onerror' + evt)); | |
| }; | |
| const blob = this.file.slice(this.offset, this.offset + CHUNK_SIZE); | |
| this.reader.readAsArrayBuffer(blob); | |
| }); | |
| } | |
| } | |
| export default FileChunker; | |