采用原生JavaScript Uint8Array
并将其转换为可读或转换Stream
的最佳方法是什么?
我想出了如何将Uint8Array变成Buffers,不确定这是否有帮助:
var uint8array = new Uint8Array();
var buffer = new Buffer(uint8array);
答案 0 :(得分:1)
让我感到满意的是使用Duplex
代替Readable
(信用转到Brian Mancini ):
import { Duplex } from 'stream';
// Or non ES6 syntax:
// const Duplex = require('stream').Duplex
let stream = new Duplex();
stream.push(buffer);
stream.push(null);
stream.pipe(process.stdout);