问题描述
我是Buffers和ReadableStreams的新手,所以这可能是一个愚蠢的问题。我有一个库作为ReadableStream的输入,但我的输入只是一个base64格式的图像。我可以像这样转换Buffer中的数据:
I'm fairly new to Buffers and ReadableStreams, so maybe this is a stupid question. I have a library that takes as input a ReadableStream, but my input is just a base64 format image. I could convert the data I have in a Buffer like so:
var img = new Buffer(img_string, 'base64');
但我不知道如何将其转换为ReadableStream或将我获得的Buffer转换为ReadableStream 。
But I have no idea how to convert it to a ReadableStream or convert the Buffer I obtained to a ReadableStream.
有没有办法做到这一点,还是我想要实现不可能?
Is there a way to do this or am I trying to achieve the impossible?
谢谢。
推荐答案
您可以使用如下所示:
// Initialize stream
var myReadableStreamBuffer = new streamBuffers.ReadableStreamBuffer({
frequency: 10, // in milliseconds.
chunkSize: 2048 // in bytes.
});
// With a buffer
myReadableStreamBuffer.put(aBuffer);
// Or with a string
myReadableStreamBuffer.put("A String", "utf8");
频率不能为0因此会引入一定的延迟。
The frequency cannot be 0 so this will introduce a certain delay.
这篇关于将缓冲区转换为nodejs中的ReadableStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!