[英]ES6 string to ReadableStream
If I have a function which accepts a ReadableStream<string>
, but I want to call it with a string
argument, is the following the easiest/best way to handle it?如果我有一个接受ReadableStream<string>
的 function ,但我想用string
参数调用它,那么以下是处理它的最简单/最好的方法吗?
const stringToStream = str => new ReadableStream({
start(controller){
controller.enqueue(str);
controller.close();
}
});
readableStreamFunc(stringToStream("foo"))
ReadableStream.from(...) is in the works ReadableStream.from(...) 正在开发中
https://github.com/whatwg/streams/issues/1018 https://github.com/whatwg/streams/issues/1018
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.