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)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。