bufferToStream.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const stream_1 = require("stream");
/**
 * buffer 转 stream
 *
 * @since 0.0.1
 * @param buffer buffer 对象
 * @returns stream 对象
 * @example
 *
 * const buf = Buffer.from('hello world');
 * const stream = bufferToStream(buf); // stream instanceof Stream
 */
function bufferToStream(buffer) {
    const stream = new stream_1.Duplex();
    stream.push(buffer);
    stream.push(null);
    return stream;
}
exports.default = bufferToStream;