Node.js - 可读流如何对仍在写入的文件做出反应? [英] Node.js - How does a readable stream react to a file that is still being written?

查看:25
本文介绍了Node.js - 可读流如何对仍在写入的文件做出反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多关于如何在 Node.js 中将数据从读取流泵送或管道传输到写入流的信息.最新版本甚至会自动暂停,并为您恢复.但是,我有不同的需求,需要一些帮助.

I have found a lot of information on how to pump, or pipe data from a read stream to a write stream in Node. The newest version even auto pauses, and resumes for you. However, I have a different need and would like some help.

我正在使用 ffmpeg 编写视频文件(写入本地文件,而不是可写流),并且我想创建一个读取流,在写入数据时读取数据.显然,读取流的速度将超过 ffmpeg 编码文件的速度.当读取流在 ffmpeg 完成写入文件之前到达数据末尾时会发生什么?我假设它会在文件完全编码之前停止读取流.

I am writing a video file using ffmpeg (to a local file, not a writeable stream), and I would like to create a readstream that reads the data as it gets written. Obviously, the read stream speed will surpass how quickly ffmpeg encodes the file. What will happen when the read stream reaches the end of data before ffmpeg finishes writing the file? I assume it will stop the read stream before the file is fully encoded.

对于暂停/恢复读取流的最佳方法,以便在编码 100% 完成之前它不会到达本地编码文件的末尾,有人有任何建议吗?

Anyone have any suggestions for the best way to pause/resume the read stream so that it doesn't reach the end of the locally encoding file until the encoding is 100% complete?

总结:

人们通常这样做:readStream --> writeStream(使用 .pipe)

This is what people normally do: readStream --> writeStream (using .pipe)

这就是我想要做的:本地文件(在缓慢的创建过程中)--> readStream

This is what I want to do: local file (in slow creation process) --> readStream

一如既往,感谢 stackOverflow 社区.

As always, thanks to the stackOverflow community.

推荐答案

成长文件 模块是什么你想要.

这篇关于Node.js - 可读流如何对仍在写入的文件做出反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆