2017-01-16 1 views

답변

1

고지 스트림을 노드 스트림으로 변환하는 내장 된 방법이없는 것 같습니다 (현재 고지 문서 당).

하지만 고지 스트림을 Node.js 스트림으로 파이프 할 수 있습니다.

따라서 코드 2 줄로 이것을 달성하려면 표준 PassThrough 스트림을 사용할 수 있습니다.

PassThrough 스트림은 기본적으로 리피터입니다. 이것은 Transform 스트림 (읽기 가능 및 쓰기 가능)의 간단한 구현입니다.

'use strict'; 
 

 
const h = require('highland'); 
 
const {PassThrough, Readable} = require('stream'); 
 

 
let stringHighlandStream = h(['a', 'b', 'c']); 
 

 
let readable = new PassThrough({objectMode: true}); 
 
stringHighlandStream.pipe(readable); 
 

 
console.log(stringHighlandStream instanceof Readable); //false 
 
console.log(readable instanceof Readable); //true 
 

 
readable.on('data', function (data) { 
 
\t console.log(data); // a, b, c or <Buffer 61> ... if you omit objectMode 
 
});

이 objectMode 플래그에 따라 문자열이나 버퍼를 방출한다.

관련 문제