Skip to content

Commit

Permalink
feat: 🎸 track number of written bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 20, 2023
1 parent 69281ff commit b80f7b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/fsa-to-node/FsaNodeWriteStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { IWriteStreamOptions } from '../node/types/options';
export class FsaNodeWriteStream extends Writable implements IWriteStream {
protected __pending__: boolean = true;
protected __closed__: boolean = false;
protected __bytes__: number = 0;
protected readonly __stream__: Promise<IFileSystemWritableFileStream>;
protected readonly __mutex__ = concurrency(1);

Expand Down Expand Up @@ -52,6 +53,7 @@ export class FsaNodeWriteStream extends Writable implements IWriteStream {
const writable = await this.__stream__;
for (const buffer of buffers) {
await writable.write(buffer);
this.__bytes__ += buffer.byteLength;
}
});
}
Expand All @@ -77,7 +79,7 @@ export class FsaNodeWriteStream extends Writable implements IWriteStream {
// ------------------------------------------------------------- IWriteStream

public get bytesWritten(): number {
return 0;
return this.__bytes__;
}

public get pending(): boolean {
Expand Down
1 change: 1 addition & 0 deletions src/fsa-to-node/__tests__/FsaNodeFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ describe('.createWriteStream()', () => {
stream.write(Buffer.from('DEF'));
stream.end();
await new Promise(resolve => stream.once('close', resolve));
expect(stream.bytesWritten).toBe(6);
expect(mfs.__vol.toJSON()).toStrictEqual({
'/mountpoint/folder/file': 'test',
'/mountpoint/folder/file2': 'ABCDEF',
Expand Down

0 comments on commit b80f7b7

Please sign in to comment.