stream.Duplex.fromWeb(pair[, options])
添加於:v17.0.0
Stability: 1 - 實驗性
參數
pair
<Object>readable
<ReadableStream>writable
WritableStream
options
<Object>- 返回: <stream.Duplex>
import { Duplex } from 'node:stream'; import { ReadableStream, WritableStream } from 'node:stream/web'; const readable = new ReadableStream({ start(controller) { controller.enqueue('world'); }, }); const writable = new WritableStream({ write(chunk) { console.log('writable', chunk); } }); const pair = { readable, writable }; const duplex = Duplex.fromWeb(pair, { encoding: 'utf8', objectMode: true }); duplex.write('hello'); for await (const chunk of duplex) { console.log('readable', chunk); }
const { Duplex } = require('node:stream'); const { ReadableStream, WritableStream } = require('node:stream/web'); const readable = new ReadableStream({ start(controller) { controller.enqueue('world'); }, }); const writable = new WritableStream({ write(chunk) { console.log('writable', chunk); } }); const pair = { readable, writable }; const duplex = Duplex.fromWeb(pair, { encoding: 'utf8', objectMode: true }); duplex.write('hello'); duplex.once('readable', () => console.log('readable', duplex.read()));
相關用法
- Node.js stream.Duplex.toWeb(streamDuplex)用法及代碼示例
- Node.js stream.Writable.uncork()用法及代碼示例
- Node.js stream.Readable.take(limit[, options])用法及代碼示例
- Node.js stream.Readable.pipe(destination[, options])用法及代碼示例
- Node.js stream.Readable.setEncoding(encoding)用法及代碼示例
- Node.js stream.Readable.some(fn[, options])用法及代碼示例
- Node.js stream.Readable.map(fn[, options])用法及代碼示例
- Node.js stream.Readable.toArray([options])用法及代碼示例
- Node.js stream.Readable.isPaused()用法及代碼示例
- Node.js stream.Readable.forEach(fn[, options])用法及代碼示例
- Node.js stream.Readable.every(fn[, options])用法及代碼示例
- Node.js stream.finished()用法及代碼示例
- Node.js stream.Readable.from()用法及代碼示例
- Node.js stream.Readable.read([size])用法及代碼示例
- Node.js stream.Readable.flatMap(fn[, options])用法及代碼示例
- Node.js stream.finished(stream[, options], callback)用法及代碼示例
- Node.js stream.Readable.unshift(chunk[, encoding])用法及代碼示例
- Node.js stream.Writable.end([chunk[, encoding]][, callback])用法及代碼示例
- Node.js stream.Readable.filter(fn[, options])用法及代碼示例
- Node.js stream.Readable.asIndexedPairs([options])用法及代碼示例
- Node.js stream.Readable.drop(limit[, options])用法及代碼示例
- Node.js stream.Readable.resume()用法及代碼示例
- Node.js stream.Readable.reduce(fn[, initial[, options]])用法及代碼示例
- Node.js stream.addAbortSignal(signal, stream)用法及代碼示例
- Node.js stream.Readable.iterator([options])用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 stream.Duplex.fromWeb(pair[, options])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。