Gathering detailed insights and metrics for @openpgp/web-stream-tools
Gathering detailed insights and metrics for @openpgp/web-stream-tools
Gathering detailed insights and metrics for @openpgp/web-stream-tools
Gathering detailed insights and metrics for @openpgp/web-stream-tools
Convenience functions for reading, transforming and working with WhatWG Streams
npm install @openpgp/web-stream-tools
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (85.3%)
TypeScript (14.7%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
30 Stars
92 Commits
14 Forks
7 Watchers
9 Branches
14 Contributors
Updated on Jun 30, 2025
Latest Version
0.1.3
Package Id
@openpgp/web-stream-tools@0.1.3
Unpacked Size
36.91 kB
Size
10.30 kB
File Count
10
NPM Version
8.15.0
Node Version
20.11.1
Published on
Jun 26, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
This library contains both basic convenience functions such as readToEnd
, concat
, slice
, clone
, and more complex functions for transforming and parsing streams. Examples of the latter can be found below.
1npm install --save @openpgp/web-stream-tools
1import * as stream from '@openpgp/web-stream-tools';
See the documentation for a full list of functions.
From v0.1, the library no longer supports native Node Readable streams in input, and instead expects Node's WebStreams. Node v17+ includes utilities to convert from and to Web Streams.
In this example we're encrypting a stream using an imaginary API which has process
and finish
methods.
1const encryptor = new Encryptor(); 2const encrypted = stream.transform(input, function process(chunk) { 3 return encryptor.process(chunk); 4}, function finish() { 5 return encryptor.finish(); 6});
Both the process
and finish
functions:
input
can be a stream containing anything, or it can be a plain value (Uint8Array or String) in which case transform()
will simply return process(input)
and finish()
concatenated together.
In this example we're encrypting a stream using an imaginary API which has a process
method that requires us to pass in chunks of size 1024 (unless it's the last chunk).
1const encrypted = stream.transformPair(input, async (readable, writable) => { 2 const reader = stream.getReader(readable); 3 const writer = stream.getWriter(writable); 4 try { 5 while (true) { 6 await writer.ready; 7 const chunk = await reader.readBytes(1024); 8 // The above will return 1024 bytes unless the stream closed before that, in which 9 // case it either returns fewer bytes or undefined if no data is available. 10 if (chunk === undefined) { 11 await writer.close(); 12 break; 13 } 14 await writer.write(encryptor.process(chunk)); 15 } 16 } catch(e) { 17 await writer.abort(e); 18 } 19});
The above example may seem more complicated than necessary, but it correctly handles:
encrypted
gets read slowly, input
gets read slowly as well)encrypted
gets canceled, input
gets cancelled as well)input
errors, encrypted
gets errored as well)Unlike transform
, transformPair
will always return a stream, even if input
is not.
There are also helper functions for reading a specific number of bytes, or a single line, etc:
1stream.parse(input, reader => { 2 const byte = await reader.readByte(); // Single byte or undefined 3 const bytes = await reader.readBytes(n); // Uint8Array of up to n bytes, or undefined 4 const line = await reader.readLine(); // Returns String up to and including the first \n, or undefined. This function is specifically for a stream of Strings. 5 // There's also peekBytes() and unshift(), which you can use to look ahead in the stream. 6 7 const stream = reader.remainder(); // New stream containing the remainder of the original stream. Only available when using a Reader from stream.parse() 8});
Most of the functions above are also available when getting a reader using stream.getReader()
instead of stream.parse()
.
All of the functions above also work when reading a stream containing Strings instead of a Uint8Arrays, and will return Strings in that case.
There are also a few functions not for reading the stream, but for manipulating the stream for another function to read:
1stream.slice(input, begin, end); // Returns a stream pointing to part of the original stream, or a Uint8Array 2stream.clone(input); // Returns a copy of the stream so that two functions can read it. Note: this does *not* clone a Uint8Array, since this function is only meant for reading the same data twice. 3stream.passiveClone(input); // Also returns a copy of the stream, but doesn't return data immediately when you read from it, only returns data when you read from the original stream. This is meant for respecting backpressure.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 4/20 approved changesets -- score normalized to 2
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More