@@ -138,8 +138,9 @@ const {
138138} = require ( 'internal/streams/iter/types' ) ;
139139
140140const {
141- toUint8Array,
142141 convertChunks,
142+ getWriterSignal,
143+ toWriterUint8Array,
143144} = require ( 'internal/streams/iter/utils' ) ;
144145
145146const {
@@ -164,7 +165,6 @@ const {
164165} = require ( 'internal/fs/promises' ) ;
165166
166167const {
167- validateAbortSignal,
168168 validateBoolean,
169169 validateFunction,
170170 validateInteger,
@@ -2197,15 +2197,14 @@ class QuicStream {
21972197 // signals backpressure additional writes are rejected until the buffer has
21982198 // capacity again.
21992199
2200- function writeSync ( chunk ) {
2200+ function writeConvertedSync ( chunk ) {
22012201 // If the stream is closed, errored, or write-ended, we cannot accept
22022202 // more data. Refuse the sync write.
22032203 // If a drain is already pending, another operation is waiting
22042204 // for capacity. Refuse the sync write.
22052205 if ( closed || errored || stream . #inner. state . writeEnded || drainWakeup != null ) {
22062206 return false ;
22072207 }
2208- chunk = toUint8Array ( chunk ) ;
22092208 const len = TypedArrayPrototypeGetByteLength ( chunk ) ;
22102209 if ( len === 0 ) return true ;
22112210 // Refuse the write only when there is no available capacity at
@@ -2223,13 +2222,18 @@ class QuicStream {
22232222 return true ;
22242223 }
22252224
2226- async function write ( chunk , options = kEmptyObject ) {
2227- validateObject ( options , 'options' ) ;
2228- const { signal } = options ;
2229- if ( signal !== undefined ) {
2230- validateAbortSignal ( signal , 'options.signal' ) ;
2231- signal . throwIfAborted ( ) ;
2232- }
2225+ function writeSync ( chunk ) {
2226+ return writeConvertedSync ( toWriterUint8Array ( chunk ) ) ;
2227+ }
2228+
2229+ function write ( chunk , options = kEmptyObject ) {
2230+ chunk = toWriterUint8Array ( chunk ) ;
2231+ const signal = getWriterSignal ( options ) ;
2232+ return writeAsync ( chunk , signal ) ;
2233+ }
2234+
2235+ async function writeAsync ( chunk , signal ) {
2236+ signal ?. throwIfAborted ( ) ;
22332237 if ( errored ) throw error ;
22342238 if ( closed || stream . #inner. state . writeEnded ) {
22352239 throw new ERR_INVALID_STATE ( 'Writer is closed' ) ;
@@ -2242,16 +2246,15 @@ class QuicStream {
22422246 throw new ERR_INVALID_STATE ( 'Stream write buffer is full' ) ;
22432247 }
22442248
2245- if ( ! writeSync ( chunk ) ) {
2249+ if ( ! writeConvertedSync ( chunk ) ) {
22462250 throw new ERR_INVALID_STATE ( 'Stream write buffer is full' ) ;
22472251 }
22482252 }
22492253
2250- function writevSync ( chunks ) {
2254+ function writevConvertedSync ( chunks ) {
22512255 if ( closed || errored || stream . #inner. state . writeEnded || drainWakeup != null ) {
22522256 return false ;
22532257 }
2254- chunks = convertChunks ( chunks ) ;
22552258 let len = 0 ;
22562259 for ( const c of chunks ) len += TypedArrayPrototypeGetByteLength ( c ) ;
22572260 if ( len === 0 ) return true ;
@@ -2262,13 +2265,18 @@ class QuicStream {
22622265 return true ;
22632266 }
22642267
2265- async function writev ( chunks , options = kEmptyObject ) {
2266- validateObject ( options , 'options' ) ;
2267- const { signal } = options ;
2268- if ( signal !== undefined ) {
2269- validateAbortSignal ( signal , 'options.signal' ) ;
2270- signal . throwIfAborted ( ) ;
2271- }
2268+ function writevSync ( chunks ) {
2269+ return writevConvertedSync ( convertChunks ( chunks ) ) ;
2270+ }
2271+
2272+ function writev ( chunks , options = kEmptyObject ) {
2273+ chunks = convertChunks ( chunks ) ;
2274+ const signal = getWriterSignal ( options ) ;
2275+ return writevAsync ( chunks , signal ) ;
2276+ }
2277+
2278+ async function writevAsync ( chunks , signal ) {
2279+ signal ?. throwIfAborted ( ) ;
22722280
22732281 if ( errored ) throw error ;
22742282 if ( closed || stream . #inner. state . writeEnded ) {
@@ -2283,7 +2291,7 @@ class QuicStream {
22832291 throw new ERR_INVALID_STATE ( 'Stream write buffer is full' ) ;
22842292 }
22852293
2286- if ( ! writevSync ( chunks ) ) {
2294+ if ( ! writevConvertedSync ( chunks ) ) {
22872295 throw new ERR_INVALID_STATE ( 'Stream write buffer is full' ) ;
22882296 }
22892297 }
@@ -2308,11 +2316,13 @@ class QuicStream {
23082316 return totalBytesWritten ;
23092317 }
23102318
2311- async function end ( options = kEmptyObject ) {
2312- validateObject ( options , 'options' ) ;
2313- const { signal } = options ;
2319+ function end ( options = kEmptyObject ) {
2320+ const signal = getWriterSignal ( options ) ;
2321+ return endAsync ( signal ) ;
2322+ }
2323+
2324+ async function endAsync ( signal ) {
23142325 if ( signal !== undefined ) {
2315- validateAbortSignal ( signal , 'options.signal' ) ;
23162326 signal . throwIfAborted ( ) ;
23172327 // TODO(@jasnell): The stream/iter spec allows individual sync end
23182328 // calls to be canceled via an AbortSignal. We currently do not support
0 commit comments