Skip to content

Commit 2d1134f

Browse files
authored
increase buffer size (#100)
* increase buffer size * fix: set buffer size on demand
1 parent 453ae66 commit 2d1134f

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/file.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,12 @@ export abstract class File implements IDisposable {
481481
this._fileStream.setLength(this._fileStream.length + bytesToAdd);
482482

483483
// Step 3: Shuffle bytes to the end
484-
const buffer = new Uint8Array(File.bufferSize);
484+
const _bufferSize = Math.min(bytesToAdd, File.BUFFER_SIZE * 1024);
485+
const buffer = new Uint8Array(_bufferSize);
485486
const stopShufflingIndex = start + replace + bytesToAdd;
486487
let shuffleIndex = this._fileStream.length;
487488
while (shuffleIndex > stopShufflingIndex) {
488-
const bytesToReplace = Math.min(shuffleIndex - stopShufflingIndex, File.bufferSize);
489+
const bytesToReplace = Math.min(shuffleIndex - stopShufflingIndex, _bufferSize);
489490

490491
// Fill up the buffer
491492
this._fileStream.seek(shuffleIndex - bytesToReplace - bytesToAdd, SeekOrigin.Begin);

0 commit comments

Comments
 (0)