@os-team/stream-length
v1.0.5
Published
Gets and validates the length of a stream.
Downloads
39
Readme
@os-team/stream-length
Gets and validates the length of a stream.
Usage
Install the package using the following command:
yarn add @os-team/stream-length
Get the length of a stream as follows:
import streamLength from '@os-team/stream-length';
(async () => {
const stream = streamLength(createReadableStream());
await consumeReadableStream(stream);
const fileSize = stream.length; // It is important to get the length after the stream has beed consumed
})();
If you want to validate the length of a stream, specify the maxLength
option:
const stream = streamLength(createReadableStream(), {
maxLength: 100,
});
To change the error message, specify the errorMessage
option:
const stream = streamLength(createReadableStream(), {
maxLength: 100,
errorMessage: 'The file must be no larger than 100 bytes',
});