stream

Buffer entire file in memory with NodeJs

旧城冷巷雨未停 提交于 2020-01-12 02:29:11
问题 I have a relatevely small file (some hundreds of kilobytes) that I want to be in memory for direct access for the entire execution of the code. I don't know exactly the internals of NodeJs, so I'm asking if a fs open is enough or I have to read all file and copy to a Buffer ? 回答1: Basically, you need to use the readFile or readFileSync function from the fs module. They return the complete content of the given file, but differ in their behavior (asynchronous versus synchronous). If blocking

XML serializing with XmlWriter via StringBuilder is utf-16 while via Stream is utf-8?

筅森魡賤 提交于 2020-01-11 18:04:21
问题 I was surprised when I encountered it, and wrote a console application to check it and make sure I wasn't doing anything else. Can anyone explain this? Here's the code: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Xml; using System.Xml.Serialization; namespace ConsoleApplication1 { public class Program { static void Main(string[] args) { var o = new SomeObject { Field1 = "string value", Field2 = 8 }; Console.WriteLine(

XML serializing with XmlWriter via StringBuilder is utf-16 while via Stream is utf-8?

孤街醉人 提交于 2020-01-11 18:04:06
问题 I was surprised when I encountered it, and wrote a console application to check it and make sure I wasn't doing anything else. Can anyone explain this? Here's the code: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Xml; using System.Xml.Serialization; namespace ConsoleApplication1 { public class Program { static void Main(string[] args) { var o = new SomeObject { Field1 = "string value", Field2 = 8 }; Console.WriteLine(

node.js : how to pipe - youtube to mp4 to mp3

本小妞迷上赌 提交于 2020-01-11 17:31:25
问题 I want to convert a youtube url into an mp3 file. Currently, I download the mp4 using node's ytdl module, like so: fs = require 'fs' ytdl = require 'ytdl' url = 'http://www.youtube.com/watch?v=v8bOTvg-iaU' mp4 = './video.mp4' ytdl(url).pipe(fs.createWriteStream(mp4)) Once the download is complete, I convert the mp4 into mp3 using the fluent-ffmpeg module, like so: ffmpeg = require 'fluent-ffmpeg' mp4 = './video.mp4' mp3 = './audio.mp3' proc = new ffmpeg({source:mp4}) proc.setFfmpegPath('

Python subprocess Popen: Send binary data to C++ on Windows

孤街浪徒 提交于 2020-01-11 11:58:16
问题 After three days of intensive googleing and stackoverflowing I more or less got my program to work. I tried a lot of stuff and found a lot of answers somehow connected to my problem, but no working solution. Sry should I have missed the right page!! I'm looking forward to comments and recommendations. Task: Send binary data (floats) from python to C++ program, get few floats back Data is going to be 20ms soundcard input, latency is a bit critical Platform: Windows (only due to drivers for the

Reading XML from Stream

爷,独闯天下 提交于 2020-01-11 08:29:08
问题 I'm working with ASP.NET, and am importing an XML file from a form. Right now I convert that into a Stream : Stream inputStream = XmlFileUploadControl.PostedFile.InputStream; because I may need this version later. I'd like to first check to make make sure that the XML file has the correct format, and, if it is, then display some information: if (CorrectFileFormat(inputStream)) { DisplayLicenseInfo(inputStream); } else { StatusLabel.Text = "Selected file is not a LicensingDiag XML file"; } The

Stop / kill WebRTC media stream

[亡魂溺海] 提交于 2020-01-11 04:58:08
问题 How to completely kill the WebRTC media stream? MediaStream.stop() is not working anymore. Testing in Chrome 47, Mac OS 10.11. 回答1: Use stream.getTracks().forEach(track => track.stop()); . stream.stop() was deprecated. 回答2: For all browsers if (microphone_data.media_stream) { microphone_data.media_stream.getTracks().forEach(function (track) { track.stop(); }); } 来源: https://stackoverflow.com/questions/34966809/stop-kill-webrtc-media-stream

Reading an InputStream into a Data object

纵然是瞬间 提交于 2020-01-11 03:08:08
问题 In Swift 3.x, we usually handle binary data using Data ; from it you can generate most other important types, and there are useful functions on it. But how do I create a Data from an InputStream ? Is there a nice way? 回答1: I could not find a nice way. We can create a nice-ish wrapper around the unsafe stuff: extension Data { init(reading input: InputStream) throws { self.init() input.open() defer { input.close() } let bufferSize = 1024 let buffer = UnsafeMutablePointer<UInt8>.allocate

C#: tail like program for text file

自作多情 提交于 2020-01-10 19:14:06
问题 I have a log file that continually logs short lines. I need to develop a service that reacts (or polls, or listens to) to new lines added to that file, a sort of unix' tail program, so that my service is always up to date reguarding the file. I don't think that opening a read stream and keeping it opened is a good idea. Maybe I should use the FileSystemWatcher class. Long story short, I need to parse in real time every new line added to this file. Any idea help or indication is really

How to add indention to the stream operator

青春壹個敷衍的年華 提交于 2020-01-10 12:39:12
问题 In our project we use the c++ stream operator (<<) in our object model to print out an easy readible format of the data. A simplified example is this: std::ostream& operator<<(std::ostream & oStream, const OwnClass& iOwnClass) { oStream << "[SomeMember1: " << iOwnClass._ownMember1 << "]\n"; oStream << "[SomeMember2: " << iOwnClass._ownMember2 << "]\n"; } Resulting in this in the logging: [SomeMember1: foo] [SomeMember2: bar] What we want now is to be able to indent the result of that operator