Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
673f5c86fb | |||
a225188e24 | |||
4fc82d0dc6 | |||
3d58a01b29 | |||
f7e9636bf6 | |||
f211cc8ddd | |||
60c8824f33 | |||
40e8e06ff1 |
22
changelog.md
22
changelog.md
@ -1,5 +1,27 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-10-16 - 3.2.4 - fix(SmartDuplex)
|
||||||
|
Fix stream termination when reading from a web readable stream
|
||||||
|
|
||||||
|
- Resolved an issue in SmartDuplex where the stream did not properly terminate after reaching the end of a web readable stream.
|
||||||
|
|
||||||
|
## 2024-10-16 - 3.2.3 - fix(smartduplex)
|
||||||
|
Enhance documentation for read function in SmartDuplex
|
||||||
|
|
||||||
|
- Added inline comments to clarify the behavior and importance of unlocking the reader in the readFunction of SmartDuplex.fromWebReadableStream.
|
||||||
|
|
||||||
|
## 2024-10-16 - 3.2.2 - fix(SmartDuplex)
|
||||||
|
Fix issue with SmartDuplex fromWebReadableStream method
|
||||||
|
|
||||||
|
- Resolved a potential unhandled promise rejection in fromWebReadableStream method
|
||||||
|
- Ensured proper release of stream reader lock in case of read completion
|
||||||
|
|
||||||
|
## 2024-10-16 - 3.2.1 - fix(core)
|
||||||
|
Fix the order of operations in SmartDuplex _read method to ensure proper waiting for items.
|
||||||
|
|
||||||
|
- Adjusted the order of reading function execution and waiting for items in the SmartDuplex _read method.
|
||||||
|
- Fixed potential issues with stream data processing timing.
|
||||||
|
|
||||||
## 2024-10-16 - 3.2.0 - feat(SmartDuplex)
|
## 2024-10-16 - 3.2.0 - feat(SmartDuplex)
|
||||||
Added method to create SmartDuplex from a WebReadableStream.
|
Added method to create SmartDuplex from a WebReadableStream.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartstream",
|
"name": "@push.rocks/smartstream",
|
||||||
"version": "3.2.0",
|
"version": "3.2.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.",
|
"description": "A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartstream',
|
name: '@push.rocks/smartstream',
|
||||||
version: '3.2.0',
|
version: '3.2.4',
|
||||||
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
||||||
}
|
}
|
||||||
|
@ -56,21 +56,19 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
|||||||
readableStream: ReadableStream<T>
|
readableStream: ReadableStream<T>
|
||||||
): SmartDuplex<T, T> {
|
): SmartDuplex<T, T> {
|
||||||
const smartDuplex = new SmartDuplex<T, T>({
|
const smartDuplex = new SmartDuplex<T, T>({
|
||||||
|
/**
|
||||||
|
* this function is called whenever the stream is being read from and at the same time if nothing is enqueued
|
||||||
|
* therefor it is important to always unlock the reader after reading
|
||||||
|
*/
|
||||||
readFunction: async () => {
|
readFunction: async () => {
|
||||||
const reader = readableStream.getReader();
|
const reader = readableStream.getReader();
|
||||||
try {
|
const { value, done } = await reader.read();
|
||||||
while (true) {
|
if (value !== undefined) {
|
||||||
const { value, done } = await reader.read();
|
smartDuplex.push(value);
|
||||||
if (value !== undefined) {
|
}
|
||||||
smartDuplex.push(value);
|
reader.releaseLock();
|
||||||
}
|
if (done) {
|
||||||
if (done) {
|
smartDuplex.push(null);
|
||||||
smartDuplex.end();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
reader.releaseLock();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -105,11 +103,11 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
|||||||
|
|
||||||
public async _read(size: number): Promise<void> {
|
public async _read(size: number): Promise<void> {
|
||||||
this.debugLog(`${this.options.name}: read was called`);
|
this.debugLog(`${this.options.name}: read was called`);
|
||||||
await this.backpressuredArray.waitForItems();
|
|
||||||
this.debugLog(`${this.options.name}: successfully waited for items.`);
|
|
||||||
if (this.options.readFunction) {
|
if (this.options.readFunction) {
|
||||||
await this.options.readFunction();
|
await this.options.readFunction();
|
||||||
}
|
}
|
||||||
|
await this.backpressuredArray.waitForItems();
|
||||||
|
this.debugLog(`${this.options.name}: successfully waited for items.`);
|
||||||
let canPushMore = true;
|
let canPushMore = true;
|
||||||
while (this.backpressuredArray.data.length > 0 && canPushMore) {
|
while (this.backpressuredArray.data.length > 0 && canPushMore) {
|
||||||
const nextChunk = this.backpressuredArray.shift();
|
const nextChunk = this.backpressuredArray.shift();
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartstream',
|
name: '@push.rocks/smartstream',
|
||||||
version: '3.2.0',
|
version: '3.2.4',
|
||||||
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user