使用Node JS将Uint8Array转换为Stream

时间:2015-08-24 21:47:20

标签: javascript arrays node.js stream

采用原生JavaScript Uint8Array并将其转换为可读或转换Stream的最佳方法是什么?

我想出了如何将Uint8Array变成Buffers,不确定这是否有帮助:

var uint8array = new Uint8Array();
var buffer = new Buffer(uint8array);

1 个答案:

答案 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);