stream.Duplex.toWeb(streamDuplex)
添加於:v17.0.0
Stability: 1 - 實驗性
參數
streamDuplex
<stream.Duplex>- 返回:<Object>
readable
<ReadableStream>writable
WritableStream
import { Duplex } from 'node:stream'; const duplex = Duplex({ objectMode: true, read() { this.push('world'); this.push(null); }, write(chunk, encoding, callback) { console.log('writable', chunk); callback(); } }); const { readable, writable } = Duplex.toWeb(duplex); writable.getWriter().write('hello'); const { value } = await readable.getReader().read(); console.log('readable', value);
const { Duplex } = require('node:stream'); const duplex = Duplex({ objectMode: true, read() { this.push('world'); this.push(null); }, write(chunk, encoding, callback) { console.log('writable', chunk); callback(); } }); const { readable, writable } = Duplex.toWeb(duplex); writable.getWriter().write('hello'); readable.getReader().read().then((result) => { console.log('readable', result.value); });
相關用法
- Node.js stream.Duplex.fromWeb(pair[, options])用法及代碼示例
- 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.toWeb(streamDuplex)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。