@gjsify/stream 0.3.21 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/_virtual/_rolldown/runtime.js +1 -0
- package/lib/esm/consumers/index.js +1 -1
- package/lib/esm/duplex.js +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/esm/internal/state.js +1 -0
- package/lib/esm/internal/types.js +0 -0
- package/lib/esm/passthrough.js +1 -0
- package/lib/esm/promises/index.js +1 -1
- package/lib/esm/readable.js +1 -0
- package/lib/esm/stream-base.js +1 -0
- package/lib/esm/transform.js +1 -0
- package/lib/esm/utils/finished.js +1 -0
- package/lib/esm/utils/pipe.js +1 -0
- package/lib/esm/utils/pipeline.js +1 -0
- package/lib/esm/writable.js +1 -0
- package/lib/types/duplex.d.ts +42 -0
- package/lib/types/index.d.ts +15 -190
- package/lib/types/internal/state.d.ts +4 -0
- package/lib/types/internal/types.d.ts +21 -0
- package/lib/types/passthrough.d.ts +5 -0
- package/lib/types/readable.d.ts +73 -0
- package/lib/types/stream-base.d.ts +26 -0
- package/lib/types/transform.d.ts +11 -0
- package/lib/types/utils/finished.d.ts +14 -0
- package/lib/types/utils/pipe.d.ts +10 -0
- package/lib/types/utils/pipeline.d.ts +7 -0
- package/lib/types/writable.d.ts +47 -0
- package/package.json +6 -6
- package/src/callable.spec.ts +39 -0
- package/src/duplex.ts +317 -0
- package/src/index.ts +49 -1633
- package/src/internal/state.ts +34 -0
- package/src/internal/types.ts +31 -0
- package/src/passthrough.ts +19 -0
- package/src/readable.ts +580 -0
- package/src/stream-base.ts +37 -0
- package/src/transform.ts +108 -0
- package/src/utils/finished.ts +156 -0
- package/src/utils/pipe.ts +113 -0
- package/src/utils/pipeline.ts +59 -0
- package/src/writable.ts +398 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
async function arrayBuffer(e){let t=[];for await(let n of e)t.push(n instanceof Uint8Array?n:new TextEncoder().encode(String(n)));let n=t.reduce((e,t)=>e+t.length,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return r.buffer}async function blob(e){let t=await arrayBuffer(e);return new Blob([t])}async function buffer(e){let t=await arrayBuffer(e);return new Uint8Array(t)}async function text(e){let t=await arrayBuffer(e);return new TextDecoder().decode(t)}async function json(e){let t=await text(e);return JSON.parse(t)}var e={arrayBuffer,blob,buffer,text,json};export{arrayBuffer,blob,buffer,e as default,json,text};
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";async function arrayBuffer(e){let t=[];for await(let n of e)t.push(n instanceof Uint8Array?n:new TextEncoder().encode(String(n)));let n=t.reduce((e,t)=>e+t.length,0),r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return r.buffer}async function blob(e){let t=await arrayBuffer(e);return new Blob([t])}async function buffer(e){let t=await arrayBuffer(e);return new Uint8Array(t)}async function text(e){let t=await arrayBuffer(e);return new TextDecoder().decode(t)}async function json(e){let t=await text(e);return JSON.parse(t)}var e={arrayBuffer,blob,buffer,text,json};export{arrayBuffer,blob,buffer,e as default,json,text};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{getDefaultHighWaterMark as e,validateHighWaterMark as t}from"./internal/state.js";import{Readable_ as n}from"./readable.js";import{nextTick as r}from"@gjsify/utils";var Duplex_=class extends n{writable=!0;writableHighWaterMark;writableLength=0;writableObjectMode;writableEnded=!1;writableFinished=!1;writableCorked=0;writableNeedDrain=!1;allowHalfOpen;_decodeStrings;_writableState={highWaterMark:0,objectMode:!1};_duplexCorkedBuffer=[];_duplexWriting=!1;_duplexWriteQueue=[];_writeImpl;_finalImpl;_defaultEncoding=`utf8`;_pendingWrites=0;_pendingEndCb=null;constructor(n){super(n),t(`writableHighWaterMark`,n?.writableHighWaterMark),t(`readableHighWaterMark`,n?.readableHighWaterMark),this.writableObjectMode=n?.writableObjectMode??n?.objectMode??!1,this.writableHighWaterMark=n?.highWaterMark??n?.writableHighWaterMark??e(this.writableObjectMode),this._writableState.highWaterMark=this.writableHighWaterMark,this._writableState.objectMode=this.writableObjectMode,n?.highWaterMark===void 0&&n?.readableHighWaterMark!==void 0&&(this.readableHighWaterMark=n.readableHighWaterMark,this._readableState.highWaterMark=n.readableHighWaterMark),n?.readableObjectMode!==void 0&&(this.readableObjectMode=n.readableObjectMode,this._readableState.objectMode=n.readableObjectMode,n?.readableHighWaterMark===void 0&&n?.highWaterMark===void 0&&(this.readableHighWaterMark=e(n.readableObjectMode),this._readableState.highWaterMark=this.readableHighWaterMark)),this.allowHalfOpen=n?.allowHalfOpen!==!1,this._decodeStrings=n?.decodeStrings!==!1,n?.write&&(this._writeImpl=n.write),n?.final&&(this._finalImpl=n.final),this.allowHalfOpen||this.once(`end`,()=>{this.writableEnded||r(()=>this.end())})}_write(e,t,n){this._writeImpl?this._writeImpl.call(this,e,t,n):n()}_final(e){this._finalImpl?this._finalImpl.call(this,e):e()}destroy(e){return this.destroyed?this:(this.writable=!1,super.destroy(e))}write(e,t,n){let i,a;if(typeof t==`function`?(i=t,a=this._defaultEncoding):(a=t??this._defaultEncoding,i=n??(()=>{})),this._decodeStrings&&!this.writableObjectMode&&typeof e==`string`){let t=globalThis.Buffer;t&&(e=t.from(e,a),a=`buffer`)}if(typeof e!=`string`&&!this.writableObjectMode){let t=globalThis.Buffer;(t&&t.isBuffer(e)||e instanceof Uint8Array)&&(a=`buffer`)}if(this.writableEnded){let e=Error(`write after end`);return r(()=>{i(e),this.emit(`error`,e)}),!1}if(this.writableLength+=this.writableObjectMode?1:chunkLen(e),this.writableCorked>0)return this._duplexCorkedBuffer.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;let o=this.writableLength<this.writableHighWaterMark;return o||(this.writableNeedDrain=!0),this._duplexDoWrite(e,a,i),o}_duplexDoWrite(e,t,n){if(this._duplexWriting){this._duplexWriteQueue.push({chunk:e,encoding:t,callback:n});return}this._duplexWriting=!0,this._duplexStartWrite(e,t,n)}_duplexStartWrite(e,t,n){this._pendingWrites++,this._write(e,t,t=>{this._pendingWrites--,this.writableLength-=this.writableObjectMode?1:chunkLen(e),r(t?()=>{if(n(t),this._duplexWriting=!1,this.emit(`error`,t),this._duplexWriteQueue.length>0){let e=this._duplexWriteQueue.shift();this._duplexWriting=!0,this._duplexStartWrite(e.chunk,e.encoding,e.callback)}}:()=>{if(n(),this._duplexWriteQueue.length>0){let e=this._duplexWriteQueue.shift();this._duplexStartWrite(e.chunk,e.encoding,e.callback);return}if(this._duplexWriting=!1,this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`)),this._pendingWrites===0&&this._pendingEndCb){let e=this._pendingEndCb;this._pendingEndCb=null,e()}})})}end(e,t,n){typeof e==`function`&&(n=e,e=void 0),typeof t==`function`&&(n=t,t=void 0),e!=null&&this.write(e,t),this.writableEnded=!0;let doFinal=()=>{this._final(e=>{this.writableFinished=!0,this._doPrefinishHooks(()=>{r(()=>{e&&this.emit(`error`,e),this.emit(`finish`),r(()=>this.emit(`close`)),n&&n()})})})};return this._pendingWrites>0||this._duplexWriting||this._duplexWriteQueue.length>0?this._pendingEndCb=doFinal:doFinal(),this}_doPrefinishHooks(e){e()}cork(){this.writableCorked++}uncork(){if(this.writableCorked>0&&(this.writableCorked--,this.writableCorked===0&&this._duplexCorkedBuffer.length>0)){let e=this._duplexCorkedBuffer.splice(0);for(let{chunk:t,encoding:n,callback:r}of e)this._write(t,n,e=>{this.writableLength-=this.writableObjectMode?1:chunkLen(t),e?(r(e),this.emit(`error`,e)):r()});this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,r(()=>this.emit(`drain`)))}}setDefaultEncoding(e){return this._defaultEncoding=e,this}};function chunkLen(e){if(e==null)return 1;let t=e.length;return typeof t==`number`?t:1}export{Duplex_};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{makeCallable as e}from"./callable.js";import{nextTick as t,queueMicrotask as n}from"@gjsify/utils";import{EventEmitter as r}from"@gjsify/events";let i=16384,a=16;function getDefaultHighWaterMark(e){return e?a:i}function setDefaultHighWaterMark(e,t){if(typeof t!=`number`||t<0||Number.isNaN(t))throw TypeError(`Invalid highWaterMark: ${t}`);e?a=t:i=t}function validateHighWaterMark(e,t){if(t!==void 0&&(typeof t!=`number`||Number.isNaN(t))){let n=TypeError(`The value of "${e}" is invalid. Received ${t}`);throw n.code=`ERR_INVALID_ARG_VALUE`,n}}var Stream_=class extends r{constructor(e){super(e)}pipe(e,t){let n=this,r=t?.end!==!1,i=!1,ondrain=()=>{i=!1,e.removeListener(`drain`,ondrain),typeof n.resume==`function`&&n.resume()},ondata=t=>{e.writable&&e.write(t)===!1&&typeof n.pause==`function`&&(n.pause(),i||(i=!0,e.on(`drain`,ondrain)))};n.on(`data`,ondata);let a=!1,onend=()=>{a||(a=!0,r&&e.end())},onclose=()=>{a||(a=!0,r&&!(n instanceof u)&&typeof e.destroy==`function`&&e.destroy())};r&&(n.on(`end`,onend),n.on(`close`,onclose));let cleanup=()=>{n.removeListener(`data`,ondata),i&&e.removeListener(`drain`,ondrain),n.removeListener(`end`,onend),n.removeListener(`close`,onclose),n.removeListener(`end`,cleanup),n.removeListener(`close`,cleanup),e.removeListener(`close`,cleanup)};return n.on(`end`,cleanup),n.on(`close`,cleanup),e.on(`close`,cleanup),n instanceof u&&(n._pipeDests.push({dest:e,cleanup}),n._readableState.pipes.push(e)),e.emit(`pipe`,n),e}},o=class Readable_ extends Stream_{readable=!0;readableFlowing=null;readableLength=0;readableHighWaterMark;readableEncoding;readableObjectMode;readableEnded=!1;readableAborted=!1;destroyed=!1;_pipeDests=[];_buffer=[];_readableState={ended:!1,endEmitted:!1,reading:!1,constructed:!0,highWaterMark:0,objectMode:!1,pipes:[]};_readablePending=!1;_readImpl;_destroyImpl;_constructImpl;constructor(e){super(e),this.readableHighWaterMark=e?.highWaterMark??getDefaultHighWaterMark(e?.objectMode??!1),this.readableEncoding=e?.encoding??null,this.readableObjectMode=e?.objectMode??!1,this._readableState.highWaterMark=this.readableHighWaterMark,this._readableState.objectMode=this.readableObjectMode,e?.read&&(this._readImpl=e.read),e?.destroy&&(this._destroyImpl=e.destroy),e?.construct&&(this._constructImpl=e.construct),(this._constructImpl||this._construct!==u.prototype._construct)&&(this._readableState.constructed=!1,t(()=>{this._construct(e=>{this._readableState.constructed=!0,e?this.destroy(e):this.readableFlowing===!0&&this._flow()})}))}_construct(e){this._constructImpl?this._constructImpl.call(this,e):e()}_read(e){this._readImpl&&this._readImpl.call(this,e)}read(e){if(!this._readableState.constructed)return null;if(this._buffer.length===0){if(this._readableState.ended)return null;this._readableState.reading=!0,this._read(e??this.readableHighWaterMark),this._readableState.reading=!1}if(this._buffer.length===0||e===0)return null;if(this.readableObjectMode){if(e===void 0){let e=this._buffer.shift();return--this.readableLength,this._readableState.ended&&this._buffer.length===0&&!this._readableState.endEmitted&&this._emitEnd(),e}if(e>this.readableLength)return null;let t=this._buffer.shift();return--this.readableLength,t}if(e!=null)return e>this.readableLength?null:this._readBytes(e);let t=this._buffer.splice(0);if(this.readableLength=0,this._readableState.ended&&this._buffer.length===0&&!this._readableState.endEmitted&&this._emitEnd(),t.length===1)return t[0];if(t.length===0)return null;if(typeof t[0]==`string`)return t.join(``);let n=globalThis.Buffer;return n?.concat?n.concat(t):t}_readBytes(e){let t=0,n=[];for(;t<e&&this._buffer.length>0;){let r=this._buffer[0],i=r.length??1;if(t+i<=e)n.push(this._buffer.shift()),t+=i,this.readableLength-=i;else{let i=e-t,a=globalThis.Buffer;a&&a.isBuffer(r),n.push(r.slice(0,i)),this._buffer[0]=r.slice(i),this.readableLength-=i,t+=i}}if(n.length===1)return n[0];let r=globalThis.Buffer;return r?.concat?r.concat(n):n}push(e,n){if(e===null)return this._readableState.ended=!0,this.readableEnded=!0,this._buffer.length===0&&!this._readableState.endEmitted&&t(()=>this._emitEnd()),this._scheduleReadable(),!1;if(!this.readableObjectMode&&!(typeof e==`string`||ArrayBuffer.isView(e))){let n=Object.assign(TypeError(`Invalid non-string/buffer chunk type: ${typeof e}`),{code:`ERR_INVALID_ARG_TYPE`});return t(()=>this.emit(`error`,n)),!1}return this._buffer.push(e),this.readableLength+=this.readableObjectMode?1:e.length??1,this.readableFlowing&&!this._flowing&&t(()=>this._flow()),this.readableFlowing!==!0&&this._scheduleReadable(),this.readableLength<this.readableHighWaterMark}_emitEnd(){this._readableState.endEmitted||(this._readableState.endEmitted=!0,this.emit(`end`),t(()=>this._autoClose()))}_autoClose(){this.emit(`close`)}_scheduleReadable(){this._readablePending||this.listenerCount(`readable`)===0||(this._readablePending=!0,t(()=>{this._readablePending=!1,this.destroyed||this.emit(`readable`)}))}on(e,t){return super.on(e,t),e===`data`&&this.readableFlowing!==!1&&this.resume(),e===`readable`&&(this._buffer.length>0||this._readableState.ended)&&this._scheduleReadable(),this}unshift(e){this._buffer.unshift(e),this.readableLength+=this.readableObjectMode?1:e.length??1}setEncoding(e){return this.readableEncoding=e,this}pause(){return this.readableFlowing=!1,this.emit(`pause`),this}resume(){return this.readableFlowing!==!0&&(this.readableFlowing=!0,this.emit(`resume`),this._readableState.constructed&&this._flow()),this}_flowing=!1;_flow(){if(!(this.readableFlowing!==!0||this._flowing||this.destroyed)&&this._readableState.constructed){this._flowing=!0;try{for(;this._buffer.length>0&&this.readableFlowing&&!this.destroyed;){let e=this._buffer.shift();if(this.readableLength-=this.readableObjectMode?1:e.length??1,this.readableEncoding&&typeof e!=`string`){let t=globalThis.Buffer;t&&t.isBuffer(e)?e=e.toString(this.readableEncoding):e instanceof Uint8Array&&(e=new TextDecoder(this.readableEncoding).decode(e))}this.emit(`data`,e)}if(this.destroyed)return;if(this._readableState.ended&&this._buffer.length===0&&!this._readableState.endEmitted){t(()=>this._emitEnd());return}!this._readableState.ended&&!this._readableState.reading&&!this.destroyed&&(this._readableState.reading=!0,this._read(this.readableHighWaterMark),this._readableState.reading=!1)}finally{this._flowing=!1}this._buffer.length>0&&this.readableFlowing&&!this.destroyed&&t(()=>this._flow())}}isPaused(){return this.readableFlowing===!1}unpipe(e){if(e){let t=this._pipeDests.findIndex(t=>t.dest===e);if(t!==-1){this._pipeDests[t].cleanup(),this._pipeDests.splice(t,1);let n=this._readableState.pipes.indexOf(e);n!==-1&&this._readableState.pipes.splice(n,1),e.emit(`unpipe`,this),this._pipeDests.length===0&&(this.readableFlowing=!1)}}else{for(let e of this._pipeDests)e.cleanup(),e.dest.emit(`unpipe`,this);this._pipeDests=[],this._readableState.pipes=[],this.readableFlowing=!1}return this}_destroy(e,t){this._destroyImpl?this._destroyImpl.call(this,e,t):t(e??void 0)}destroy(e){if(this.destroyed)return this;this.destroyed=!0,this.readable=!1,this.readableAborted=!this.readableEnded,e&&(this._err=e);let cb=e=>{e&&t(()=>this.emit(`error`,e)),t(()=>this.emit(`close`))};return Object.prototype.hasOwnProperty.call(this,`_destroy`)?this._destroy(e??null,cb):this._destroyImpl?this._destroyImpl.call(this,e??null,cb):cb(e),this}static toWeb(e){return new ReadableStream({start(t){e.on(`data`,e=>{typeof e==`string`?t.enqueue(new TextEncoder().encode(e)):e instanceof Uint8Array?t.enqueue(e):e&&typeof e.length==`number`&&t.enqueue(new Uint8Array(e))}),e.on(`end`,()=>{t.close()}),e.on(`error`,e=>{t.error(e)})},cancel(){e.destroy()}})}static fromWeb(e,t){let n=e.getReader();return new Readable_({...t,read(){n.read().then(({done:e,value:t})=>{e?this.push(null):this.push(t)},e=>{this.destroy(e)})},destroy(e,t){n.cancel(e?.message).then(()=>t(null),t)}})}[Symbol.asyncIterator](){let e=this,t=[],n=!1,r=null,i=null,a=null;return e.on(`data`,e=>{if(i){let t=i;i=null,a=null,t({value:e,done:!1})}else t.push(e)}),e.on(`end`,()=>{if(n=!0,i){let e=i;i=null,a=null,e({value:void 0,done:!0})}}),e.on(`error`,e=>{if(r=e,n=!0,a){let t=a;i=null,a=null,t(e)}}),{next(){return r?Promise.reject(r):t.length>0?Promise.resolve({value:t.shift(),done:!1}):n?Promise.resolve({value:void 0,done:!0}):new Promise((e,t)=>{i=e,a=t})},return(){return e.destroy(),Promise.resolve({value:void 0,done:!0})},[Symbol.asyncIterator](){return this}}}static from(e,t){let n=new u({objectMode:!0,...t,read(){}});return typeof e==`string`||ArrayBuffer.isView(e)?(n.push(e),n.push(null),n):((async()=>{try{for await(let t of e)n.push(t)||await new Promise(e=>n.once(`drain`,e));n.push(null)}catch(e){n.destroy(e)}})(),n)}},s=class Writable_ extends Stream_{static[Symbol.hasInstance](e){return this.prototype!==void 0&&Object.prototype.isPrototypeOf.call(this.prototype,e)?!0:this.prototype===Writable_.prototype?e!=null&&typeof e.writableHighWaterMark==`number`:!1}writable=!0;writableHighWaterMark;writableLength=0;writableObjectMode;writableEnded=!1;writableFinished=!1;writableCorked=0;writableNeedDrain=!1;destroyed=!1;_writableState={ended:!1,finished:!1,constructed:!0,writing:!1};_corkedBuffer=[];_writeBuffer=[];_pendingConstruct=[];_ending=!1;_endCallback;_pendingEnd=null;_writeImpl;_writev;_finalImpl;_destroyImpl;_constructImpl;_decodeStrings;_defaultEncoding=`utf8`;constructor(e){super(e),this.writableHighWaterMark=e?.highWaterMark??getDefaultHighWaterMark(e?.objectMode??!1),this.writableObjectMode=e?.objectMode??!1,this._decodeStrings=e?.decodeStrings!==!1,e?.write&&(this._writeImpl=e.write),e?.writev&&(this._writev=e.writev),e?.final&&(this._finalImpl=e.final),e?.destroy&&(this._destroyImpl=e.destroy),e?.construct&&(this._constructImpl=e.construct),(this._constructImpl||this._construct!==d.prototype._construct)&&(this._writableState.constructed=!1,t(()=>{this._construct(e=>{this._writableState.constructed=!0,e?this.destroy(e):this._maybeFlush()})}))}_construct(e){this._constructImpl?this._constructImpl.call(this,e):e()}_write(e,t,n){this._writeImpl?this._writeImpl.call(this,e,t,n):n()}_final(e){this._finalImpl?this._finalImpl.call(this,e):e()}_maybeFlush(){let e=this._pendingConstruct.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}if(this._pendingEnd){let{chunk:e,encoding:t,callback:n}=this._pendingEnd;this._pendingEnd=null,this._doEnd(e,t,n)}}_doWrite(e,n,r){this._writableState.writing=!0;let i=!0;this._write(e,n,n=>{if(this.writableLength-=this.writableObjectMode?1:e?.length??1,i){t(()=>{if(n){r(n),this.emit(`error`,n);return}r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}),n||this._drainWriteBuffer();return}t(n?()=>{r(n),this.emit(`error`,n),this._drainWriteBuffer()}:()=>{r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`)),this._drainWriteBuffer()})}),i=!1}_drainWriteBuffer(){if(this._writeBuffer.length>0){let e=this._writeBuffer.shift();this._doWrite(e.chunk,e.encoding,e.callback)}else this._writableState.writing=!1,this._maybeFinish()}_maybeFinish(){!this._ending||this._writableState.finished||this._writableState.writing||this._writeBuffer.length>0||(this._ending=!1,this._final(e=>{this.writableFinished=!0,this._writableState.finished=!0,t(()=>{e&&this.emit(`error`,e),this.emit(`finish`),t(()=>this.emit(`close`)),this._endCallback&&this._endCallback()})}))}write(e,n,callback){if(typeof n==`function`&&(callback=n,n=void 0),n===void 0&&(n=this._defaultEncoding),callback||=(()=>{}),this._decodeStrings&&!this.writableObjectMode&&typeof e==`string`){let t=globalThis.Buffer;t&&(e=t.from(e,n),n=`buffer`)}if(typeof e!=`string`&&!this.writableObjectMode){let t=globalThis.Buffer;(t&&t.isBuffer(e)||e instanceof Uint8Array)&&(n=`buffer`)}if(this.writableEnded){let e=Error(`write after end`);return t(()=>{callback&&callback(e),this.emit(`error`,e)}),!1}if(this.writableLength+=this.writableObjectMode?1:e?.length??1,this.writableCorked>0)return this._corkedBuffer.push({chunk:e,encoding:n,callback}),this.writableLength<this.writableHighWaterMark;if(!this._writableState.constructed)return this._pendingConstruct.push({chunk:e,encoding:n,callback}),this.writableLength<this.writableHighWaterMark;let r=this.writableLength<this.writableHighWaterMark;return r||(this.writableNeedDrain=!0),this._writableState.writing?this._writeBuffer.push({chunk:e,encoding:n,callback}):this._doWrite(e,n,callback),r}_doEnd(e,t,n){e!=null&&this.write(e,t),this.writableEnded=!0,this._writableState.ended=!0,this._ending=!0,this._endCallback=n,this._maybeFinish()}end(e,n,r){return typeof e==`function`&&(r=e,e=void 0),typeof n==`function`&&(r=n,n=void 0),this.writableEnded?(r&&t(r),this):this._writableState.constructed?(this._doEnd(e,n,r),this):(this._pendingEnd={chunk:e,encoding:n,callback:r},this)}cork(){this.writableCorked++}uncork(){this.writableCorked>0&&(this.writableCorked--,this.writableCorked===0&&this._corkedBuffer.length>0&&this._flushCorkedBuffer())}_flushCorkedBuffer(){if(this._writev&&this._corkedBuffer.length>1){let e=this._corkedBuffer.splice(0),t=e.map(e=>({chunk:e.chunk,encoding:e.encoding}));this._writev.call(this,t,t=>{for(let t of e)this.writableLength-=this.writableObjectMode?1:t.chunk?.length??1;if(t){for(let n of e)n.callback(t);this.emit(`error`,t)}else{for(let t of e)t.callback();this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}})}else{let e=this._corkedBuffer.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}}}setDefaultEncoding(e){return this._defaultEncoding=e,this}destroy(e){if(this.destroyed)return this;this.destroyed=!0,this.writable=!1,e&&(this._err=e);let cb=e=>{e&&t(()=>this.emit(`error`,e)),t(()=>this.emit(`close`))};return this._destroyImpl?this._destroyImpl.call(this,e??null,cb):cb(e),this}},Duplex_=class extends o{writable=!0;writableHighWaterMark;writableLength=0;writableObjectMode;writableEnded=!1;writableFinished=!1;writableCorked=0;writableNeedDrain=!1;allowHalfOpen;_decodeStrings;_writableState={highWaterMark:0,objectMode:!1};_duplexCorkedBuffer=[];_duplexWriting=!1;_duplexWriteQueue=[];_writeImpl;_finalImpl;_defaultEncoding=`utf8`;_pendingWrites=0;_pendingEndCb=null;constructor(e){super(e),validateHighWaterMark(`writableHighWaterMark`,e?.writableHighWaterMark),validateHighWaterMark(`readableHighWaterMark`,e?.readableHighWaterMark),this.writableObjectMode=e?.writableObjectMode??e?.objectMode??!1,this.writableHighWaterMark=e?.highWaterMark??e?.writableHighWaterMark??getDefaultHighWaterMark(this.writableObjectMode),this._writableState.highWaterMark=this.writableHighWaterMark,this._writableState.objectMode=this.writableObjectMode,e?.highWaterMark===void 0&&e?.readableHighWaterMark!==void 0&&(this.readableHighWaterMark=e.readableHighWaterMark,this._readableState.highWaterMark=e.readableHighWaterMark),e?.readableObjectMode!==void 0&&(this.readableObjectMode=e.readableObjectMode,this._readableState.objectMode=e.readableObjectMode,e?.readableHighWaterMark===void 0&&e?.highWaterMark===void 0&&(this.readableHighWaterMark=getDefaultHighWaterMark(e.readableObjectMode),this._readableState.highWaterMark=this.readableHighWaterMark)),this.allowHalfOpen=e?.allowHalfOpen!==!1,this._decodeStrings=e?.decodeStrings!==!1,e?.write&&(this._writeImpl=e.write),e?.final&&(this._finalImpl=e.final),this.allowHalfOpen||this.once(`end`,()=>{this.writableEnded||t(()=>this.end())})}_write(e,t,n){this._writeImpl?this._writeImpl.call(this,e,t,n):n()}_final(e){this._finalImpl?this._finalImpl.call(this,e):e()}destroy(e){return this.destroyed?this:(this.writable=!1,super.destroy(e))}write(e,n,r){if(typeof n==`function`&&(r=n,n=void 0),n===void 0&&(n=this._defaultEncoding),this._decodeStrings&&!this.writableObjectMode&&typeof e==`string`){let t=globalThis.Buffer;t&&(e=t.from(e,n),n=`buffer`)}if(typeof e!=`string`&&!this.writableObjectMode){let t=globalThis.Buffer;(t&&t.isBuffer(e)||e instanceof Uint8Array)&&(n=`buffer`)}if(this.writableEnded){let e=Error(`write after end`),n=r||(()=>{});return t(()=>{n(e),this.emit(`error`,e)}),!1}if(this.writableLength+=this.writableObjectMode?1:e?.length??1,this.writableCorked>0)return this._duplexCorkedBuffer.push({chunk:e,encoding:n,callback:r||(()=>{})}),this.writableLength<this.writableHighWaterMark;let i=this.writableLength<this.writableHighWaterMark;i||(this.writableNeedDrain=!0);let a=r||(()=>{});return this._duplexDoWrite(e,n,a),i}_duplexDoWrite(e,t,n){if(this._duplexWriting){this._duplexWriteQueue.push({chunk:e,encoding:t,callback:n});return}this._duplexWriting=!0,this._duplexStartWrite(e,t,n)}_duplexStartWrite(e,n,r){this._pendingWrites++,this._write(e,n,n=>{this._pendingWrites--,this.writableLength-=this.writableObjectMode?1:e?.length??1,t(n?()=>{if(r(n),this._duplexWriting=!1,this.emit(`error`,n),this._duplexWriteQueue.length>0){let e=this._duplexWriteQueue.shift();this._duplexWriting=!0,this._duplexStartWrite(e.chunk,e.encoding,e.callback)}}:()=>{if(r(),this._duplexWriteQueue.length>0){let e=this._duplexWriteQueue.shift();this._duplexStartWrite(e.chunk,e.encoding,e.callback);return}if(this._duplexWriting=!1,this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`)),this._pendingWrites===0&&this._pendingEndCb){let e=this._pendingEndCb;this._pendingEndCb=null,e()}})})}_duplexDrainQueue(){if(this._duplexWriteQueue.length>0){let e=this._duplexWriteQueue.shift();this._duplexDoWrite(e.chunk,e.encoding,e.callback)}}end(e,n,r){typeof e==`function`&&(r=e,e=void 0),typeof n==`function`&&(r=n,n=void 0),e!=null&&this.write(e,n),this.writableEnded=!0;let doFinal=()=>{this._final(e=>{this.writableFinished=!0,this._doPrefinishHooks(()=>{t(()=>{e&&this.emit(`error`,e),this.emit(`finish`),t(()=>this.emit(`close`)),r&&r()})})})};return this._pendingWrites>0||this._duplexWriting||this._duplexWriteQueue.length>0?this._pendingEndCb=doFinal:doFinal(),this}_doPrefinishHooks(e){e()}cork(){this.writableCorked++}uncork(){if(this.writableCorked>0&&(this.writableCorked--,this.writableCorked===0&&this._duplexCorkedBuffer.length>0)){let e=this._duplexCorkedBuffer.splice(0);for(let{chunk:t,encoding:n,callback:r}of e)this._write(t,n,e=>{this.writableLength-=this.writableObjectMode?1:t?.length??1,e?(r(e),this.emit(`error`,e)):r()});this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,t(()=>this.emit(`drain`)))}}setDefaultEncoding(e){return this._defaultEncoding=e,this}},c=class Transform_ extends Duplex_{constructor(e){super({...e,write:void 0,final:void 0}),e?.transform&&(this._transform=e.transform),e?.flush&&(this._flush=e.flush),e?.final&&(this._final=e.final)}_transform(e,t,n){throw Object.assign(Error(`The _transform() method is not implemented`),{code:`ERR_METHOD_NOT_IMPLEMENTED`})}_flush(e){e()}_write(e,n,r){let i=!1;try{this._transform(e,n,(e,n)=>{if(i){let e=Object.assign(Error(`Callback called multiple times`),{code:`ERR_MULTIPLE_CALLBACK`});t(()=>this.emit(`error`,e));return}if(i=!0,e){r(e);return}n!=null&&this.push(n),r()})}catch(e){if(e?.code===`ERR_METHOD_NOT_IMPLEMENTED`)throw e;r(e)}}_final(e){this._flush((t,n)=>{if(t){e(t);return}n!=null&&this.push(n),this.push(null),e()})}_doPrefinishHooks(e){let t=Transform_.prototype._final;this._final===t?e():t.call(this,e)}},PassThrough_=class extends c{constructor(e){super({...e,transform(e,t,n){n(null,e)}})}};function pipeline(...e){let t=typeof e[e.length-1]==`function`?e.pop():void 0,n=e;if(n.length<2)throw Error(`pipeline requires at least 2 streams`);let r=null;function onError(e){if(!r){r=e;for(let e of n)typeof e.destroy==`function`&&e.destroy();t&&t(e)}}let i=n[0];for(let e=1;e<n.length;e++){let t=n[e];i.pipe(t),i.on(`error`,onError),i=t}let a=n[n.length-1];return a.on(`error`,onError),a.on(`finish`,()=>{t&&!r&&t(null)}),a}function finished(e,t,r){let i;i=typeof t==`function`?t:r;let a=!1;function done(e){a||(a=!0,i(e))}let onFinish=()=>done(),onEnd=()=>done(),onError=e=>done(e),onClose=()=>{!e.writableFinished&&!e.readableEnded&&done(Error(`premature close`))};e.on(`finish`,onFinish),e.on(`end`,onEnd),e.on(`error`,onError),e.on(`close`,onClose);let o=typeof e.write==`function`,s=typeof e.read==`function`,c=e.writableFinished===!0,l=e.readableEnded===!0;if(e.destroyed===!0){let t=e._err;n(t?()=>done(t):o&&c||s&&l?()=>done():()=>done(Error(`premature close`)))}else (o&&!s&&c||!o&&s&&l||o&&s&&c&&l)&&n(()=>done());return function(){e.removeListener(`finish`,onFinish),e.removeListener(`end`,onEnd),e.removeListener(`error`,onError),e.removeListener(`close`,onClose)}}function addAbortSignal(e,t){if(!(e instanceof AbortSignal))throw TypeError(`The first argument must be an AbortSignal`);if(!(t instanceof l))throw TypeError(`The second argument must be a Stream`);if(e.aborted)t.destroy(Error(`The operation was aborted`));else{let onAbort=()=>{t.destroy(Error(`The operation was aborted`))};e.addEventListener(`abort`,onAbort,{once:!0}),t.once(`close`,()=>{e.removeEventListener(`abort`,onAbort)})}return t}function isReadable(e){if(e==null)return!1;let t=e;return typeof t.readable!=`boolean`||typeof t.read!=`function`||t.destroyed===!0||t.readableEnded===!0?!1:t.readable===!0}function isWritable(e){if(e==null)return!1;let t=e;return typeof t.writable!=`boolean`||typeof t.write!=`function`||t.destroyed===!0||t.writableEnded===!0?!1:t.writable===!0}function isDestroyed(e){return e==null?!1:e.destroyed===!0}function isDisturbed(e){if(e==null)return!1;let t=e;return t.readableDidRead===!0||t.readableFlowing!==null&&t.readableFlowing!==void 0}function isErrored(e){if(e==null)return!1;let t=e;return t.destroyed===!0&&typeof t.readable==`boolean`&&t.readable===!1||t.destroyed===!0&&typeof t.writable==`boolean`&&t.writable===!1}const l=e(Stream_),u=e(o),d=e(s),f=e(Duplex_),p=e(c),m=e(PassThrough_),h=Object.assign(l,{Stream:l,Readable:u,Writable:d,Duplex:f,Transform:p,PassThrough:m,pipeline,finished,addAbortSignal,isReadable,isWritable,isDestroyed,isDisturbed,isErrored,getDefaultHighWaterMark,setDefaultHighWaterMark});export{f as Duplex,m as PassThrough,u as Readable,l as Stream,p as Transform,d as Writable,addAbortSignal,h as default,finished,getDefaultHighWaterMark,isDestroyed,isDisturbed,isErrored,isReadable,isWritable,pipeline,setDefaultHighWaterMark};
|
|
1
|
+
import{makeCallable as e}from"./callable.js";import{Stream_ as t}from"./stream-base.js";import{getDefaultHighWaterMark as n,setDefaultHighWaterMark as r}from"./internal/state.js";import{Readable_ as i}from"./readable.js";import{Duplex_ as a}from"./duplex.js";import"./utils/pipe.js";import{Writable_ as o}from"./writable.js";import{Transform_ as s}from"./transform.js";import{PassThrough_ as c}from"./passthrough.js";import{pipeline as l}from"./utils/pipeline.js";import{addAbortSignal as u,finished as d,isDestroyed as f,isDisturbed as p,isErrored as m,isReadable as h,isWritable as g}from"./utils/finished.js";const _=e(t),v=e(i),y=e(o),b=e(a),x=e(s),S=e(c),C=Object.assign(_,{Stream:_,Readable:v,Writable:y,Duplex:b,Transform:x,PassThrough:S,pipeline:l,finished:d,addAbortSignal:u,isReadable:h,isWritable:g,isDestroyed:f,isDisturbed:p,isErrored:m,getDefaultHighWaterMark:n,setDefaultHighWaterMark:r});export{b as Duplex,S as PassThrough,v as Readable,_ as Stream,x as Transform,y as Writable,u as addAbortSignal,C as default,d as finished,n as getDefaultHighWaterMark,f as isDestroyed,p as isDisturbed,m as isErrored,h as isReadable,g as isWritable,l as pipeline,r as setDefaultHighWaterMark};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";let e=16384,t=16;function getDefaultHighWaterMark(n){return n?t:e}function setDefaultHighWaterMark(n,r){if(typeof r!=`number`||r<0||Number.isNaN(r))throw TypeError(`Invalid highWaterMark: ${r}`);n?t=r:e=r}function validateHighWaterMark(e,t){if(t!==void 0&&(typeof t!=`number`||Number.isNaN(t))){let n=TypeError(`The value of "${e}" is invalid. Received ${t}`);throw n.code=`ERR_INVALID_ARG_VALUE`,n}}export{getDefaultHighWaterMark,setDefaultHighWaterMark,validateHighWaterMark};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Transform_ as e}from"./transform.js";var PassThrough_=class extends e{constructor(e){super({...e,transform(e,t,n){n(null,e)}})}};export{PassThrough_};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{pipeline as e}from"../utils/pipeline.js";import{finished as t}from"../utils/finished.js";import"../index.js";function pipeline(...t){return new Promise((n,r)=>{e(...t,e=>{e?r(e):n()})})}function finished(e,n){return new Promise((r,i)=>{n&&typeof n!=`function`?t(e,n,e=>{e?i(e):r()}):t(e,e=>{e?i(e):r()})})}var n={pipeline,finished};export{n as default,finished,pipeline};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Stream_ as e}from"./stream-base.js";import{getDefaultHighWaterMark as t}from"./internal/state.js";import{nextTick as n}from"@gjsify/utils";function chunkLength(e){if(e==null)return 1;let t=e.length;return typeof t==`number`?t:1}function sliceChunk(e,t,n){if(typeof e==`string`)return n===void 0?e.slice(t):e.slice(t,n);let r=e.slice;return typeof r==`function`?r.call(e,t,n):e}var r=class Readable_ extends e{readable=!0;readableFlowing=null;readableLength=0;readableHighWaterMark;readableEncoding;readableObjectMode;readableEnded=!1;readableAborted=!1;destroyed=!1;_pipeDests=[];_buffer=[];_readableState={ended:!1,endEmitted:!1,reading:!1,constructed:!0,highWaterMark:0,objectMode:!1,pipes:[]};_err;_readablePending=!1;_readImpl;_destroyImpl;_constructImpl;constructor(e){super(e),this.readableHighWaterMark=e?.highWaterMark??t(e?.objectMode??!1),this.readableEncoding=e?.encoding??null,this.readableObjectMode=e?.objectMode??!1,this._readableState.highWaterMark=this.readableHighWaterMark,this._readableState.objectMode=this.readableObjectMode,e?.read&&(this._readImpl=e.read),e?.destroy&&(this._destroyImpl=e.destroy),e?.construct&&(this._constructImpl=e.construct),(this._constructImpl||this._construct!==Readable_.prototype._construct)&&(this._readableState.constructed=!1,n(()=>{this._construct(e=>{this._readableState.constructed=!0,e?this.destroy(e):this.readableFlowing===!0&&this._flow()})}))}_construct(e){this._constructImpl?this._constructImpl.call(this,e):e()}_read(e){this._readImpl&&this._readImpl.call(this,e)}read(e){if(!this._readableState.constructed)return null;if(this._buffer.length===0){if(this._readableState.ended)return null;this._readableState.reading=!0,this._read(e??this.readableHighWaterMark),this._readableState.reading=!1}if(this._buffer.length===0||e===0)return null;if(this.readableObjectMode){if(e===void 0){let e=this._buffer.shift();return--this.readableLength,this._readableState.ended&&this._buffer.length===0&&!this._readableState.endEmitted&&this._emitEnd(),e}if(e>this.readableLength)return null;let t=this._buffer.shift();return--this.readableLength,t}if(e!=null)return e>this.readableLength?null:this._readBytes(e);let t=this._buffer.splice(0);if(this.readableLength=0,this._readableState.ended&&this._buffer.length===0&&!this._readableState.endEmitted&&this._emitEnd(),t.length===1)return t[0];if(t.length===0)return null;if(typeof t[0]==`string`)return t.join(``);let n=globalThis.Buffer;return n?.concat?n.concat(t):t}_readBytes(e){let t=0,n=[];for(;t<e&&this._buffer.length>0;){let r=this._buffer[0],i=chunkLength(r);if(t+i<=e)n.push(this._buffer.shift()),t+=i,this.readableLength-=i;else{let i=e-t;n.push(sliceChunk(r,0,i)),this._buffer[0]=sliceChunk(r,i),this.readableLength-=i,t+=i}}if(n.length===1)return n[0];let r=globalThis.Buffer;return r?.concat?r.concat(n):n}push(e,t){if(e===null)return this._readableState.ended=!0,this.readableEnded=!0,this._buffer.length===0&&!this._readableState.endEmitted&&n(()=>this._emitEnd()),this._scheduleReadable(),!1;if(!this.readableObjectMode&&!(typeof e==`string`||ArrayBuffer.isView(e))){let t=Object.assign(TypeError(`Invalid non-string/buffer chunk type: ${typeof e}`),{code:`ERR_INVALID_ARG_TYPE`});return n(()=>this.emit(`error`,t)),!1}return this._buffer.push(e),this.readableLength+=this.readableObjectMode?1:chunkLength(e),this.readableFlowing&&!this._flowing&&n(()=>this._flow()),this.readableFlowing!==!0&&this._scheduleReadable(),this.readableLength<this.readableHighWaterMark}_emitEnd(){this._readableState.endEmitted||(this._readableState.endEmitted=!0,this.emit(`end`),n(()=>this._autoClose()))}_autoClose(){this.emit(`close`)}_scheduleReadable(){this._readablePending||this.listenerCount(`readable`)===0||(this._readablePending=!0,n(()=>{this._readablePending=!1,this.destroyed||this.emit(`readable`)}))}on(e,t){return super.on(e,t),e===`data`&&this.readableFlowing!==!1&&this.resume(),e===`readable`&&(this._buffer.length>0||this._readableState.ended)&&this._scheduleReadable(),this}unshift(e){this._buffer.unshift(e),this.readableLength+=this.readableObjectMode?1:chunkLength(e)}setEncoding(e){return this.readableEncoding=e,this}pause(){return this.readableFlowing=!1,this.emit(`pause`),this}resume(){return this.readableFlowing!==!0&&(this.readableFlowing=!0,this.emit(`resume`),this._readableState.constructed&&this._flow()),this}_flowing=!1;_flow(){if(!(this.readableFlowing!==!0||this._flowing||this.destroyed)&&this._readableState.constructed){this._flowing=!0;try{for(;this._buffer.length>0&&this.readableFlowing&&!this.destroyed;){let e=this._buffer.shift();if(this.readableLength-=this.readableObjectMode?1:chunkLength(e),this.readableEncoding&&typeof e!=`string`){let t=globalThis.Buffer;t?.isBuffer&&t.isBuffer(e)?e=e.toString(this.readableEncoding):e instanceof Uint8Array&&(e=new TextDecoder(this.readableEncoding).decode(e))}this.emit(`data`,e)}if(this.destroyed)return;if(this._readableState.ended&&this._buffer.length===0&&!this._readableState.endEmitted){n(()=>this._emitEnd());return}!this._readableState.ended&&!this._readableState.reading&&!this.destroyed&&(this._readableState.reading=!0,this._read(this.readableHighWaterMark),this._readableState.reading=!1)}finally{this._flowing=!1}this._buffer.length>0&&this.readableFlowing&&!this.destroyed&&n(()=>this._flow())}}isPaused(){return this.readableFlowing===!1}unpipe(e){if(e){let t=this._pipeDests.findIndex(t=>t.dest===e);if(t!==-1){this._pipeDests[t].cleanup(),this._pipeDests.splice(t,1);let n=this._readableState.pipes.indexOf(e);n!==-1&&this._readableState.pipes.splice(n,1),e.emit(`unpipe`,this),this._pipeDests.length===0&&(this.readableFlowing=!1)}}else{for(let e of this._pipeDests)e.cleanup(),e.dest.emit(`unpipe`,this);this._pipeDests=[],this._readableState.pipes=[],this.readableFlowing=!1}return this}_destroy(e,t){this._destroyImpl?this._destroyImpl.call(this,e,t):t(e??void 0)}destroy(e){if(this.destroyed)return this;this.destroyed=!0,this.readable=!1,this.readableAborted=!this.readableEnded,e&&(this._err=e);let cb=e=>{e&&n(()=>this.emit(`error`,e)),n(()=>this.emit(`close`))};return Object.prototype.hasOwnProperty.call(this,`_destroy`)?this._destroy(e??null,cb):this._destroyImpl?this._destroyImpl.call(this,e??null,cb):cb(e),this}static toWeb(e){return new ReadableStream({start(t){e.on(`data`,e=>{typeof e==`string`?t.enqueue(new TextEncoder().encode(e)):e instanceof Uint8Array?t.enqueue(e):e&&typeof e.length==`number`&&t.enqueue(new Uint8Array(e))}),e.on(`end`,()=>{t.close()}),e.on(`error`,e=>{t.error(e)})},cancel(){e.destroy()}})}static fromWeb(e,t){let n=e.getReader();return new Readable_({...t,read(){n.read().then(({done:e,value:t})=>{e?this.push(null):this.push(t)},e=>{this.destroy(e)})},destroy(e,t){n.cancel(e?.message).then(()=>t(null),t)}})}[Symbol.asyncIterator](){let e=this,t=[],n=!1,r=null,i=null,a=null;return e.on(`data`,e=>{if(i){let t=i;i=null,a=null,t({value:e,done:!1})}else t.push(e)}),e.on(`end`,()=>{if(n=!0,i){let e=i;i=null,a=null,e({value:void 0,done:!0})}}),e.on(`error`,e=>{if(r=e,n=!0,a){let t=a;i=null,a=null,t(e)}}),{next(){return r?Promise.reject(r):t.length>0?Promise.resolve({value:t.shift(),done:!1}):n?Promise.resolve({value:void 0,done:!0}):new Promise((e,t)=>{i=e,a=t})},return(){return e.destroy(),Promise.resolve({value:void 0,done:!0})},[Symbol.asyncIterator](){return this}}}static from(e,t){let n=new Readable_({objectMode:!0,...t,read(){}});return typeof e==`string`||ArrayBuffer.isView(e)?(n.push(e),n.push(null),n):((async()=>{try{for await(let t of e)n.push(t)||await new Promise(e=>n.once(`drain`,e));n.push(null)}catch(e){n.destroy(e)}})(),n)}};export{r as Readable_};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{EventEmitter as e}from"@gjsify/events";let t;function _setPipeImpl(e){t=e}var Stream_=class extends e{constructor(e){super(e)}pipe(e,n){return t(this,e,n)}};export{Stream_,_setPipeImpl};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Duplex_ as e}from"./duplex.js";import{nextTick as t}from"@gjsify/utils";var n=class Transform_ extends e{constructor(e){super({...e,write:void 0,final:void 0});let t=this;e?.transform&&(t._transform=e.transform),e?.flush&&(t._flush=e.flush),e?.final&&(t._final=e.final)}_transform(e,t,n){throw Object.assign(Error(`The _transform() method is not implemented`),{code:`ERR_METHOD_NOT_IMPLEMENTED`})}_flush(e){e()}_write(e,n,r){let i=!1;try{this._transform(e,n,(e,n)=>{if(i){let e=Object.assign(Error(`Callback called multiple times`),{code:`ERR_MULTIPLE_CALLBACK`});t(()=>this.emit(`error`,e));return}if(i=!0,e){r(e);return}n!=null&&this.push(n),r()})}catch(e){if(e?.code===`ERR_METHOD_NOT_IMPLEMENTED`)throw e;r(e)}}_final(e){this._flush((t,n)=>{if(t){e(t);return}n!=null&&this.push(n),this.push(null),e()})}_doPrefinishHooks(e){let t=Transform_.prototype._final;this._final===t?e():t.call(this,e)}};export{n as Transform_};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{Stream_ as e}from"../stream-base.js";import{queueMicrotask as t}from"@gjsify/utils";function finished(e,n,r){let i;i=typeof n==`function`?n:r;let a=!1;function done(e){a||(a=!0,i(e))}let onFinish=()=>done(),onEnd=()=>done(),onError=e=>done(e),onClose=()=>{let t=e,n=e;!t.writableFinished&&!n.readableEnded&&done(Error(`premature close`))};e.on(`finish`,onFinish),e.on(`end`,onEnd),e.on(`error`,onError),e.on(`close`,onClose);let o=e,s=typeof e.write==`function`,c=typeof e.read==`function`,l=o.writableFinished===!0,u=o.readableEnded===!0;if(o.destroyed===!0){let e=o._err;t(e?()=>done(e):s&&l||c&&u?()=>done():()=>done(Error(`premature close`)))}else (s&&!c&&l||!s&&c&&u||s&&c&&l&&u)&&t(()=>done());return function cleanup(){e.removeListener(`finish`,onFinish),e.removeListener(`end`,onEnd),e.removeListener(`error`,onError),e.removeListener(`close`,onClose)}}function addAbortSignal(t,n){if(!(t instanceof AbortSignal))throw TypeError(`The first argument must be an AbortSignal`);if(!(n instanceof e))throw TypeError(`The second argument must be a Stream`);let r=n;if(t.aborted)r.destroy(Error(`The operation was aborted`));else{let onAbort=()=>{r.destroy(Error(`The operation was aborted`))};t.addEventListener(`abort`,onAbort,{once:!0}),n.once(`close`,()=>{t.removeEventListener(`abort`,onAbort)})}return n}function isReadable(e){if(e==null)return!1;let t=e;return typeof t.readable!=`boolean`||typeof t.read!=`function`||t.destroyed===!0||t.readableEnded===!0?!1:t.readable===!0}function isWritable(e){if(e==null)return!1;let t=e;return typeof t.writable!=`boolean`||typeof t.write!=`function`||t.destroyed===!0||t.writableEnded===!0?!1:t.writable===!0}function isDestroyed(e){return e==null?!1:e.destroyed===!0}function isDisturbed(e){if(e==null)return!1;let t=e;return t.readableDidRead===!0||t.readableFlowing!==null&&t.readableFlowing!==void 0}function isErrored(e){if(e==null)return!1;let t=e;return t.destroyed===!0&&typeof t.readable==`boolean`&&t.readable===!1||t.destroyed===!0&&typeof t.writable==`boolean`&&t.writable===!1}export{addAbortSignal,finished,isDestroyed,isDisturbed,isErrored,isReadable,isWritable};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{_setPipeImpl as e}from"../stream-base.js";import{Readable_ as t}from"../readable.js";function pipe(e,n,r){let i=e,a=r?.end!==!1,o=!1,ondrain=()=>{o=!1,n.removeListener(`drain`,ondrain);let e=i;typeof e.resume==`function`&&e.resume()},ondata=e=>{if(n.writable){let t=i;n.write(e)===!1&&typeof t.pause==`function`&&(t.pause(),o||(o=!0,n.on(`drain`,ondrain)))}};i.on(`data`,ondata);let s=!1,onend=()=>{s||(s=!0,a&&n.end())},onclose=()=>{if(!s&&(s=!0,a&&!(i instanceof t))){let e=n;typeof e.destroy==`function`&&e.destroy()}};a&&(i.on(`end`,onend),i.on(`close`,onclose));let cleanup=()=>{i.removeListener(`data`,ondata),o&&n.removeListener(`drain`,ondrain),i.removeListener(`end`,onend),i.removeListener(`close`,onclose),i.removeListener(`end`,cleanup),i.removeListener(`close`,cleanup),n.removeListener(`close`,cleanup)};return i.on(`end`,cleanup),i.on(`close`,cleanup),n.on(`close`,cleanup),i instanceof t&&(i._pipeDests.push({dest:n,cleanup}),i._readableState.pipes.push(n)),n.emit(`pipe`,i),n}e(pipe);export{pipe};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";function pipeline(...e){let t=e,n=typeof t[t.length-1]==`function`?t.pop():void 0,r=t;if(r.length<2)throw Error(`pipeline requires at least 2 streams`);let i=null;function onError(e){if(!i){i=e;for(let e of r)typeof e.destroy==`function`&&e.destroy();n&&n(e)}}let a=r[0];for(let e=1;e<r.length;e++){let t=r[e];a.pipe(t),a.on(`error`,onError),a=t}let o=r[r.length-1];return o.on(`error`,onError),o.on(`finish`,()=>{n&&!i&&n(null)}),o}export{pipeline};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Stream_ as e}from"./stream-base.js";import{getDefaultHighWaterMark as t}from"./internal/state.js";import{nextTick as n}from"@gjsify/utils";var r=class Writable_ extends e{static[Symbol.hasInstance](e){let t=this;return t.prototype!==void 0&&Object.prototype.isPrototypeOf.call(t.prototype,e)?!0:t.prototype!==Writable_.prototype||e==null?!1:typeof e.writableHighWaterMark==`number`}writable=!0;writableHighWaterMark;writableLength=0;writableObjectMode;writableEnded=!1;writableFinished=!1;writableCorked=0;writableNeedDrain=!1;destroyed=!1;_err;_writableState={ended:!1,finished:!1,constructed:!0,writing:!1};_corkedBuffer=[];_writeBuffer=[];_pendingConstruct=[];_ending=!1;_endCallback;_pendingEnd=null;_writeImpl;_writev;_finalImpl;_destroyImpl;_constructImpl;_decodeStrings;_defaultEncoding=`utf8`;constructor(e){super(e),this.writableHighWaterMark=e?.highWaterMark??t(e?.objectMode??!1),this.writableObjectMode=e?.objectMode??!1,this._decodeStrings=e?.decodeStrings!==!1,e?.write&&(this._writeImpl=e.write),e?.writev&&(this._writev=e.writev),e?.final&&(this._finalImpl=e.final),e?.destroy&&(this._destroyImpl=e.destroy),e?.construct&&(this._constructImpl=e.construct),(this._constructImpl||this._construct!==Writable_.prototype._construct)&&(this._writableState.constructed=!1,n(()=>{this._construct(e=>{this._writableState.constructed=!0,e?this.destroy(e):this._maybeFlush()})}))}_construct(e){this._constructImpl?this._constructImpl.call(this,e):e()}_write(e,t,n){this._writeImpl?this._writeImpl.call(this,e,t,n):n()}_final(e){this._finalImpl?this._finalImpl.call(this,e):e()}_maybeFlush(){let e=this._pendingConstruct.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}if(this._pendingEnd){let{chunk:e,encoding:t,callback:n}=this._pendingEnd;this._pendingEnd=null,this._doEnd(e,t,n)}}_doWrite(e,t,r){this._writableState.writing=!0;let i=!0;this._write(e,t,t=>{if(this.writableLength-=this.writableObjectMode?1:chunkLen(e),i){n(()=>{if(t){r(t),this.emit(`error`,t);return}r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}),t||this._drainWriteBuffer();return}n(t?()=>{r(t),this.emit(`error`,t),this._drainWriteBuffer()}:()=>{r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`)),this._drainWriteBuffer()})}),i=!1}_drainWriteBuffer(){if(this._writeBuffer.length>0){let e=this._writeBuffer.shift();this._doWrite(e.chunk,e.encoding,e.callback)}else this._writableState.writing=!1,this._maybeFinish()}_maybeFinish(){!this._ending||this._writableState.finished||this._writableState.writing||this._writeBuffer.length>0||(this._ending=!1,this._final(e=>{this.writableFinished=!0,this._writableState.finished=!0,n(()=>{e&&this.emit(`error`,e),this.emit(`finish`),n(()=>this.emit(`close`)),this._endCallback&&this._endCallback()})}))}write(e,t,r){let i,a;if(typeof t==`function`?(i=t,a=this._defaultEncoding):(a=t??this._defaultEncoding,i=r??(()=>{})),this._decodeStrings&&!this.writableObjectMode&&typeof e==`string`){let t=globalThis.Buffer;t&&(e=t.from(e,a),a=`buffer`)}if(typeof e!=`string`&&!this.writableObjectMode){let t=globalThis.Buffer;(t&&t.isBuffer(e)||e instanceof Uint8Array)&&(a=`buffer`)}if(this.writableEnded){let e=Error(`write after end`);return n(()=>{i(e),this.emit(`error`,e)}),!1}if(this.writableLength+=this.writableObjectMode?1:chunkLen(e),this.writableCorked>0)return this._corkedBuffer.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;if(!this._writableState.constructed)return this._pendingConstruct.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;let o=this.writableLength<this.writableHighWaterMark;return o||(this.writableNeedDrain=!0),this._writableState.writing?this._writeBuffer.push({chunk:e,encoding:a,callback:i}):this._doWrite(e,a,i),o}_doEnd(e,t,n){e!=null&&this.write(e,t),this.writableEnded=!0,this._writableState.ended=!0,this._ending=!0,this._endCallback=n,this._maybeFinish()}end(e,t,r){return typeof e==`function`&&(r=e,e=void 0),typeof t==`function`&&(r=t,t=void 0),this.writableEnded?(r&&n(r),this):this._writableState.constructed?(this._doEnd(e,t,r),this):(this._pendingEnd={chunk:e,encoding:t,callback:r},this)}cork(){this.writableCorked++}uncork(){this.writableCorked>0&&(this.writableCorked--,this.writableCorked===0&&this._corkedBuffer.length>0&&this._flushCorkedBuffer())}_flushCorkedBuffer(){if(this._writev&&this._corkedBuffer.length>1){let e=this._corkedBuffer.splice(0),t=e.map(e=>({chunk:e.chunk,encoding:e.encoding}));this._writev.call(this,t,t=>{for(let t of e)this.writableLength-=this.writableObjectMode?1:chunkLen(t.chunk);if(t){for(let n of e)n.callback(t);this.emit(`error`,t)}else{for(let t of e)t.callback();this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}})}else{let e=this._corkedBuffer.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}}}setDefaultEncoding(e){return this._defaultEncoding=e,this}destroy(e){if(this.destroyed)return this;this.destroyed=!0,this.writable=!1,e&&(this._err=e);let cb=e=>{e&&n(()=>this.emit(`error`,e)),n(()=>this.emit(`close`))};return this._destroyImpl?this._destroyImpl.call(this,e??null,cb):cb(e),this}};function chunkLen(e){if(e==null)return 1;let t=e.length;return typeof t==`number`?t:1}export{r as Writable_};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DuplexOptions } from 'node:stream';
|
|
2
|
+
import { Readable_ } from './readable.js';
|
|
3
|
+
import type { ErrCallback } from './internal/types.js';
|
|
4
|
+
interface DuplexWritableState {
|
|
5
|
+
highWaterMark: number;
|
|
6
|
+
objectMode: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Duplex_ extends Readable_ {
|
|
9
|
+
writable: boolean;
|
|
10
|
+
writableHighWaterMark: number;
|
|
11
|
+
writableLength: number;
|
|
12
|
+
writableObjectMode: boolean;
|
|
13
|
+
writableEnded: boolean;
|
|
14
|
+
writableFinished: boolean;
|
|
15
|
+
writableCorked: number;
|
|
16
|
+
writableNeedDrain: boolean;
|
|
17
|
+
allowHalfOpen: boolean;
|
|
18
|
+
private _decodeStrings;
|
|
19
|
+
_writableState: DuplexWritableState;
|
|
20
|
+
private _duplexCorkedBuffer;
|
|
21
|
+
private _duplexWriting;
|
|
22
|
+
private _duplexWriteQueue;
|
|
23
|
+
private _writeImpl;
|
|
24
|
+
private _finalImpl;
|
|
25
|
+
private _defaultEncoding;
|
|
26
|
+
private _pendingWrites;
|
|
27
|
+
private _pendingEndCb;
|
|
28
|
+
constructor(opts?: DuplexOptions);
|
|
29
|
+
_write(chunk: unknown, encoding: string, callback: ErrCallback): void;
|
|
30
|
+
_final(callback: ErrCallback): void;
|
|
31
|
+
destroy(error?: Error): this;
|
|
32
|
+
write(chunk: unknown, encoding?: string | ErrCallback, callback?: ErrCallback): boolean;
|
|
33
|
+
private _duplexDoWrite;
|
|
34
|
+
private _duplexStartWrite;
|
|
35
|
+
end(chunk?: unknown | (() => void), encoding?: string | (() => void), callback?: () => void): this;
|
|
36
|
+
/** Hook for subclasses to run logic between _final and 'finish'. Default: no-op. */
|
|
37
|
+
protected _doPrefinishHooks(cb: () => void): void;
|
|
38
|
+
cork(): void;
|
|
39
|
+
uncork(): void;
|
|
40
|
+
setDefaultEncoding(encoding: string): this;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,193 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
cleanup: () => void;
|
|
17
|
-
}
|
|
18
|
-
declare class Stream_ extends EventEmitter {
|
|
19
|
-
constructor(opts?: StreamOptions);
|
|
20
|
-
pipe<T extends Writable>(destination: T, options?: {
|
|
21
|
-
end?: boolean;
|
|
22
|
-
}): T;
|
|
23
|
-
}
|
|
24
|
-
declare class Readable_ extends Stream_ {
|
|
25
|
-
readable: boolean;
|
|
26
|
-
readableFlowing: boolean | null;
|
|
27
|
-
readableLength: number;
|
|
28
|
-
readableHighWaterMark: number;
|
|
29
|
-
readableEncoding: string | null;
|
|
30
|
-
readableObjectMode: boolean;
|
|
31
|
-
readableEnded: boolean;
|
|
32
|
-
readableAborted: boolean;
|
|
33
|
-
destroyed: boolean;
|
|
34
|
-
/** @internal Tracked pipe destinations for unpipe. */
|
|
35
|
-
_pipeDests: PipeState[];
|
|
36
|
-
private _buffer;
|
|
37
|
-
_readableState: {
|
|
38
|
-
ended: boolean;
|
|
39
|
-
endEmitted: boolean;
|
|
40
|
-
reading: boolean;
|
|
41
|
-
constructed: boolean;
|
|
42
|
-
highWaterMark: number;
|
|
43
|
-
objectMode: boolean;
|
|
44
|
-
pipes: any[];
|
|
45
|
-
};
|
|
46
|
-
private _readablePending;
|
|
47
|
-
private _readImpl;
|
|
48
|
-
private _destroyImpl;
|
|
49
|
-
private _constructImpl;
|
|
50
|
-
constructor(opts?: ReadableOptions);
|
|
51
|
-
_construct(callback: (error?: Error | null) => void): void;
|
|
52
|
-
_read(_size: number): void;
|
|
53
|
-
read(size?: number): any;
|
|
54
|
-
/** @internal Extract exactly `size` bytes from the internal buffer. */
|
|
55
|
-
private _readBytes;
|
|
56
|
-
push(chunk: any, encoding?: string): boolean;
|
|
57
|
-
/** Emit 'end' followed by 'close' (matches Node.js autoDestroy behavior). */
|
|
58
|
-
private _emitEnd;
|
|
59
|
-
/** Override in subclasses to suppress automatic 'close' after 'end'. */
|
|
60
|
-
protected _autoClose(): void;
|
|
61
|
-
/** Schedule a single 'readable' event per microtask cycle (deduplicates multiple pushes). */
|
|
62
|
-
private _scheduleReadable;
|
|
63
|
-
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
64
|
-
unshift(chunk: any): void;
|
|
65
|
-
setEncoding(encoding: string): this;
|
|
66
|
-
pause(): this;
|
|
67
|
-
resume(): this;
|
|
68
|
-
private _flowing;
|
|
69
|
-
private _flow;
|
|
70
|
-
isPaused(): boolean;
|
|
71
|
-
unpipe(destination?: Writable): this;
|
|
72
|
-
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
73
|
-
destroy(error?: Error): this;
|
|
74
|
-
/**
|
|
75
|
-
* Converts this Node.js Readable to a Web ReadableStream.
|
|
76
|
-
* Used by @hono/node-server to bridge Node.js HTTP → Web Standard Request.
|
|
77
|
-
*/
|
|
78
|
-
static toWeb(nodeReadable: Readable_): ReadableStream<Uint8Array>;
|
|
79
|
-
/**
|
|
80
|
-
* Creates a Node.js Readable from a Web ReadableStream.
|
|
81
|
-
*/
|
|
82
|
-
static fromWeb(webStream: ReadableStream<Uint8Array>, options?: ReadableOptions): Readable_;
|
|
83
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<unknown>;
|
|
84
|
-
static from(iterable: Iterable<unknown> | AsyncIterable<unknown>, opts?: ReadableOptions): Readable;
|
|
85
|
-
}
|
|
86
|
-
declare class Writable_ extends Stream_ {
|
|
87
|
-
static [Symbol.hasInstance](obj: any): boolean;
|
|
88
|
-
writable: boolean;
|
|
89
|
-
writableHighWaterMark: number;
|
|
90
|
-
writableLength: number;
|
|
91
|
-
writableObjectMode: boolean;
|
|
92
|
-
writableEnded: boolean;
|
|
93
|
-
writableFinished: boolean;
|
|
94
|
-
writableCorked: number;
|
|
95
|
-
writableNeedDrain: boolean;
|
|
96
|
-
destroyed: boolean;
|
|
97
|
-
private _writableState;
|
|
98
|
-
private _corkedBuffer;
|
|
99
|
-
private _writeBuffer;
|
|
100
|
-
private _pendingConstruct;
|
|
101
|
-
private _ending;
|
|
102
|
-
private _endCallback?;
|
|
103
|
-
private _pendingEnd;
|
|
104
|
-
private _writeImpl;
|
|
105
|
-
private _writev;
|
|
106
|
-
private _finalImpl;
|
|
107
|
-
private _destroyImpl;
|
|
108
|
-
private _constructImpl;
|
|
109
|
-
private _decodeStrings;
|
|
110
|
-
private _defaultEncoding;
|
|
111
|
-
constructor(opts?: WritableOptions);
|
|
112
|
-
_construct(callback: (error?: Error | null) => void): void;
|
|
113
|
-
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
114
|
-
_final(callback: (error?: Error | null) => void): void;
|
|
115
|
-
private _maybeFlush;
|
|
116
|
-
private _doWrite;
|
|
117
|
-
private _drainWriteBuffer;
|
|
118
|
-
private _maybeFinish;
|
|
119
|
-
write(chunk: any, encoding?: string | ((error?: Error | null) => void), callback?: (error?: Error | null) => void): boolean;
|
|
120
|
-
private _doEnd;
|
|
121
|
-
end(chunk?: any, encoding?: string | (() => void), callback?: () => void): this;
|
|
122
|
-
cork(): void;
|
|
123
|
-
uncork(): void;
|
|
124
|
-
private _flushCorkedBuffer;
|
|
125
|
-
setDefaultEncoding(encoding: string): this;
|
|
126
|
-
destroy(error?: Error): this;
|
|
127
|
-
}
|
|
128
|
-
declare class Duplex_ extends Readable_ {
|
|
129
|
-
writable: boolean;
|
|
130
|
-
writableHighWaterMark: number;
|
|
131
|
-
writableLength: number;
|
|
132
|
-
writableObjectMode: boolean;
|
|
133
|
-
writableEnded: boolean;
|
|
134
|
-
writableFinished: boolean;
|
|
135
|
-
writableCorked: number;
|
|
136
|
-
writableNeedDrain: boolean;
|
|
137
|
-
allowHalfOpen: boolean;
|
|
138
|
-
private _decodeStrings;
|
|
139
|
-
_writableState: {
|
|
140
|
-
highWaterMark: number;
|
|
141
|
-
objectMode: boolean;
|
|
142
|
-
};
|
|
143
|
-
private _duplexCorkedBuffer;
|
|
144
|
-
private _duplexWriting;
|
|
145
|
-
private _duplexWriteQueue;
|
|
146
|
-
private _writeImpl;
|
|
147
|
-
private _finalImpl;
|
|
148
|
-
private _defaultEncoding;
|
|
149
|
-
private _pendingWrites;
|
|
150
|
-
private _pendingEndCb;
|
|
151
|
-
constructor(opts?: DuplexOptions);
|
|
152
|
-
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
153
|
-
_final(callback: (error?: Error | null) => void): void;
|
|
154
|
-
destroy(error?: Error): this;
|
|
155
|
-
write(chunk: any, encoding?: string | ((error?: Error | null) => void), callback?: (error?: Error | null) => void): boolean;
|
|
156
|
-
private _duplexDoWrite;
|
|
157
|
-
private _duplexStartWrite;
|
|
158
|
-
private _duplexDrainQueue;
|
|
159
|
-
end(chunk?: any, encoding?: string | (() => void), callback?: () => void): this;
|
|
160
|
-
/** Hook for subclasses to run logic between _final and 'finish'. Default: no-op. */
|
|
161
|
-
protected _doPrefinishHooks(cb: () => void): void;
|
|
162
|
-
cork(): void;
|
|
163
|
-
uncork(): void;
|
|
164
|
-
setDefaultEncoding(encoding: string): this;
|
|
165
|
-
}
|
|
166
|
-
declare class Transform_ extends Duplex_ {
|
|
167
|
-
constructor(opts?: TransformOptions);
|
|
168
|
-
_transform(_chunk: any, _encoding: string, _callback: (error?: Error | null, data?: any) => void): void;
|
|
169
|
-
_flush(callback: (error?: Error | null, data?: any) => void): void;
|
|
170
|
-
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
171
|
-
_final(callback: (error?: Error | null) => void): void;
|
|
172
|
-
protected _doPrefinishHooks(cb: () => void): void;
|
|
173
|
-
}
|
|
174
|
-
declare class PassThrough_ extends Transform_ {
|
|
175
|
-
constructor(opts?: TransformOptions);
|
|
176
|
-
}
|
|
177
|
-
type PipelineCallback = (err: Error | null) => void;
|
|
178
|
-
/** A stream that can be destroyed (duck-typed for pipeline). */
|
|
179
|
-
interface DestroyableStream extends Stream {
|
|
180
|
-
destroy?(error?: Error): void;
|
|
181
|
-
}
|
|
182
|
-
export declare function pipeline(...args: [...streams: DestroyableStream[], callback: PipelineCallback] | DestroyableStream[]): DestroyableStream;
|
|
183
|
-
export declare function finished(stream: Stream | Readable | Writable, callback: (err?: Error | null) => void): () => void;
|
|
184
|
-
export declare function finished(stream: Stream | Readable | Writable, opts: FinishedOptions, callback: (err?: Error | null) => void): () => void;
|
|
185
|
-
export declare function addAbortSignal(signal: AbortSignal, stream: Stream): typeof stream;
|
|
186
|
-
export declare function isReadable(stream: unknown): boolean;
|
|
187
|
-
export declare function isWritable(stream: unknown): boolean;
|
|
188
|
-
export declare function isDestroyed(stream: unknown): boolean;
|
|
189
|
-
export declare function isDisturbed(stream: unknown): boolean;
|
|
190
|
-
export declare function isErrored(stream: unknown): boolean;
|
|
1
|
+
import { Stream_ } from './stream-base.js';
|
|
2
|
+
import { Readable_ } from './readable.js';
|
|
3
|
+
import './utils/pipe.js';
|
|
4
|
+
import { Writable_ } from './writable.js';
|
|
5
|
+
import { Duplex_ } from './duplex.js';
|
|
6
|
+
import { Transform_ } from './transform.js';
|
|
7
|
+
import { PassThrough_ } from './passthrough.js';
|
|
8
|
+
import { pipeline } from './utils/pipeline.js';
|
|
9
|
+
import { finished, addAbortSignal, isReadable, isWritable, isDestroyed, isDisturbed, isErrored } from './utils/finished.js';
|
|
10
|
+
import { getDefaultHighWaterMark, setDefaultHighWaterMark } from './internal/state.js';
|
|
11
|
+
export { getDefaultHighWaterMark, setDefaultHighWaterMark };
|
|
12
|
+
export { pipeline, finished, addAbortSignal };
|
|
13
|
+
export { isReadable, isWritable, isDestroyed, isDisturbed, isErrored };
|
|
14
|
+
export type { ReadableOptions, WritableOptions, DuplexOptions, TransformOptions, FinishedOptions } from 'node:stream';
|
|
15
|
+
export type { StreamOptions } from './internal/types.js';
|
|
191
16
|
export declare const Stream: typeof Stream_;
|
|
192
17
|
export declare const Readable: typeof Readable_;
|
|
193
18
|
export declare const Writable: typeof Writable_;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function getDefaultHighWaterMark(objectMode: boolean): number;
|
|
2
|
+
export declare function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
|
|
3
|
+
/** Validate a named high-water-mark option and throw ERR_INVALID_ARG_VALUE on NaN/non-number. */
|
|
4
|
+
export declare function validateHighWaterMark(name: string, value: unknown): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EventEmitter } from '@gjsify/events';
|
|
2
|
+
/** Base options accepted by the Stream constructor (superset used by subclass options). */
|
|
3
|
+
export interface StreamOptions {
|
|
4
|
+
highWaterMark?: number;
|
|
5
|
+
objectMode?: boolean;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
captureRejections?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** A stream-like emitter that may have `pause` and `resume` methods (duck-typed). */
|
|
10
|
+
export interface StreamLike extends EventEmitter {
|
|
11
|
+
pause?(): void;
|
|
12
|
+
resume?(): void;
|
|
13
|
+
}
|
|
14
|
+
/** Internal write-buffer entry shared by Writable and Duplex queues. */
|
|
15
|
+
export interface BufferedWrite {
|
|
16
|
+
chunk: unknown;
|
|
17
|
+
encoding: string;
|
|
18
|
+
callback: (error?: Error | null) => void;
|
|
19
|
+
}
|
|
20
|
+
/** Generic node-style error callback. */
|
|
21
|
+
export type ErrCallback = (error?: Error | null) => void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ReadableOptions } from 'node:stream';
|
|
2
|
+
import { Stream_ } from './stream-base.js';
|
|
3
|
+
import type { ErrCallback } from './internal/types.js';
|
|
4
|
+
import type { PipeState } from './utils/pipe.js';
|
|
5
|
+
import type { Writable_ } from './writable.js';
|
|
6
|
+
/** Internal readable-side state — exposed via `_readableState` for npm-stream consumers. */
|
|
7
|
+
export interface ReadableInternalState {
|
|
8
|
+
ended: boolean;
|
|
9
|
+
endEmitted: boolean;
|
|
10
|
+
reading: boolean;
|
|
11
|
+
constructed: boolean;
|
|
12
|
+
highWaterMark: number;
|
|
13
|
+
objectMode: boolean;
|
|
14
|
+
pipes: Writable_[];
|
|
15
|
+
}
|
|
16
|
+
export declare class Readable_ extends Stream_ {
|
|
17
|
+
readable: boolean;
|
|
18
|
+
readableFlowing: boolean | null;
|
|
19
|
+
readableLength: number;
|
|
20
|
+
readableHighWaterMark: number;
|
|
21
|
+
readableEncoding: string | null;
|
|
22
|
+
readableObjectMode: boolean;
|
|
23
|
+
readableEnded: boolean;
|
|
24
|
+
readableAborted: boolean;
|
|
25
|
+
destroyed: boolean;
|
|
26
|
+
/** @internal Tracked pipe destinations for unpipe. */
|
|
27
|
+
_pipeDests: PipeState[];
|
|
28
|
+
/** @internal The internal data buffer. */
|
|
29
|
+
private _buffer;
|
|
30
|
+
/** @internal Mirrors Node's `_readableState`; exposed for npm-stream consumers. */
|
|
31
|
+
_readableState: ReadableInternalState;
|
|
32
|
+
/** @internal The error a `destroy(err)` call stored before the 'error' event fired. */
|
|
33
|
+
_err?: Error;
|
|
34
|
+
private _readablePending;
|
|
35
|
+
private _readImpl;
|
|
36
|
+
private _destroyImpl;
|
|
37
|
+
private _constructImpl;
|
|
38
|
+
constructor(opts?: ReadableOptions);
|
|
39
|
+
_construct(callback: ErrCallback): void;
|
|
40
|
+
_read(_size: number): void;
|
|
41
|
+
read(size?: number): unknown;
|
|
42
|
+
/** @internal Extract exactly `size` bytes from the internal buffer. */
|
|
43
|
+
private _readBytes;
|
|
44
|
+
push(chunk: unknown, _encoding?: string): boolean;
|
|
45
|
+
/** Emit 'end' followed by 'close' (matches Node.js autoDestroy behavior). */
|
|
46
|
+
private _emitEnd;
|
|
47
|
+
/** Override in subclasses to suppress automatic 'close' after 'end'. */
|
|
48
|
+
protected _autoClose(): void;
|
|
49
|
+
/** Schedule a single 'readable' event per microtask cycle (deduplicates multiple pushes). */
|
|
50
|
+
private _scheduleReadable;
|
|
51
|
+
on(event: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
52
|
+
unshift(chunk: unknown): void;
|
|
53
|
+
setEncoding(encoding: string): this;
|
|
54
|
+
pause(): this;
|
|
55
|
+
resume(): this;
|
|
56
|
+
private _flowing;
|
|
57
|
+
private _flow;
|
|
58
|
+
isPaused(): boolean;
|
|
59
|
+
unpipe(destination?: Writable_): this;
|
|
60
|
+
_destroy(error: Error | null, callback: ErrCallback): void;
|
|
61
|
+
destroy(error?: Error): this;
|
|
62
|
+
/**
|
|
63
|
+
* Converts this Node.js Readable to a Web ReadableStream.
|
|
64
|
+
* Used by @hono/node-server to bridge Node.js HTTP → Web Standard Request.
|
|
65
|
+
*/
|
|
66
|
+
static toWeb(nodeReadable: Readable_): ReadableStream<Uint8Array>;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a Node.js Readable from a Web ReadableStream.
|
|
69
|
+
*/
|
|
70
|
+
static fromWeb(webStream: ReadableStream<Uint8Array>, options?: ReadableOptions): Readable_;
|
|
71
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<unknown>;
|
|
72
|
+
static from(iterable: Iterable<unknown> | AsyncIterable<unknown>, opts?: ReadableOptions): Readable_;
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EventEmitter } from '@gjsify/events';
|
|
2
|
+
import type { StreamOptions } from './internal/types.js';
|
|
3
|
+
import type { Writable_ } from './writable.js';
|
|
4
|
+
/**
|
|
5
|
+
* Late-bound pipe implementation. Wired by `./utils/pipe.ts` when it loads —
|
|
6
|
+
* doing this lazily breaks what would otherwise be a top-level import cycle:
|
|
7
|
+
* stream-base → pipe → readable → stream-base.
|
|
8
|
+
*
|
|
9
|
+
* GJS / esbuild's `__esmMin` wrapper evaluates modules eagerly on first import
|
|
10
|
+
* but stops at the cycle boundary, so `Readable_` would be `undefined` at the
|
|
11
|
+
* point `Stream_` is declared (`class Readable_ extends Stream_` then fails
|
|
12
|
+
* with "class heritage … is not an object or null"). The hook is set after
|
|
13
|
+
* both classes finish initializing.
|
|
14
|
+
*/
|
|
15
|
+
declare let pipeImpl: <T extends Writable_>(source: Stream_, dest: T, opts?: {
|
|
16
|
+
end?: boolean;
|
|
17
|
+
}) => T;
|
|
18
|
+
/** @internal Wired by ./utils/pipe.js (side-effect import in ./readable.ts). */
|
|
19
|
+
export declare function _setPipeImpl(fn: typeof pipeImpl): void;
|
|
20
|
+
export declare class Stream_ extends EventEmitter {
|
|
21
|
+
constructor(opts?: StreamOptions);
|
|
22
|
+
pipe<T extends Writable_>(destination: T, options?: {
|
|
23
|
+
end?: boolean;
|
|
24
|
+
}): T;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TransformOptions } from 'node:stream';
|
|
2
|
+
import { Duplex_ } from './duplex.js';
|
|
3
|
+
import type { ErrCallback } from './internal/types.js';
|
|
4
|
+
export declare class Transform_ extends Duplex_ {
|
|
5
|
+
constructor(opts?: TransformOptions);
|
|
6
|
+
_transform(_chunk: unknown, _encoding: string, _callback: (error?: Error | null, data?: unknown) => void): void;
|
|
7
|
+
_flush(callback: (error?: Error | null, data?: unknown) => void): void;
|
|
8
|
+
_write(chunk: unknown, encoding: string, callback: ErrCallback): void;
|
|
9
|
+
_final(callback: ErrCallback): void;
|
|
10
|
+
protected _doPrefinishHooks(cb: () => void): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FinishedOptions } from 'node:stream';
|
|
2
|
+
import { Stream_ } from '../stream-base.js';
|
|
3
|
+
import type { Readable_ } from '../readable.js';
|
|
4
|
+
import type { Writable_ } from '../writable.js';
|
|
5
|
+
type AnyStream = Stream_ | Readable_ | Writable_;
|
|
6
|
+
export declare function finished(stream: AnyStream, callback: (err?: Error | null) => void): () => void;
|
|
7
|
+
export declare function finished(stream: AnyStream, opts: FinishedOptions, callback: (err?: Error | null) => void): () => void;
|
|
8
|
+
export declare function addAbortSignal<T extends AnyStream>(signal: AbortSignal, stream: T): T;
|
|
9
|
+
export declare function isReadable(stream: unknown): boolean;
|
|
10
|
+
export declare function isWritable(stream: unknown): boolean;
|
|
11
|
+
export declare function isDestroyed(stream: unknown): boolean;
|
|
12
|
+
export declare function isDisturbed(stream: unknown): boolean;
|
|
13
|
+
export declare function isErrored(stream: unknown): boolean;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Stream_ } from '../stream-base.js';
|
|
2
|
+
import type { Writable_ } from '../writable.js';
|
|
3
|
+
/** Tracked pipe destination for unpipe support. */
|
|
4
|
+
export interface PipeState {
|
|
5
|
+
dest: Writable_;
|
|
6
|
+
cleanup: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function pipe<T extends Writable_>(sourceStream: Stream_, destination: T, options?: {
|
|
9
|
+
end?: boolean;
|
|
10
|
+
}): T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Stream_ } from '../stream-base.js';
|
|
2
|
+
export type PipelineCallback = (err: Error | null) => void;
|
|
3
|
+
/** A stream that can be destroyed (duck-typed for pipeline). */
|
|
4
|
+
export interface DestroyableStream extends Stream_ {
|
|
5
|
+
destroy?(error?: Error): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function pipeline(...args: [...streams: DestroyableStream[], callback: PipelineCallback] | DestroyableStream[]): DestroyableStream;
|