Is there a NodeJS ‘passthrough’ stream?

Yeah. Actually, by that very name. 🙂 stream.PassThrough It’s available with Node 0.10 and later as part of the Streams 2 update (mentioned at the end). It’s also one of the few types from Streams that can be directly instantiated: var pass = new stream.PassThrough(); And, it’s currently documented briefly under API for Stream Implementors … Read more

How to write unitTest for methods using a stream as a parameter

Use a MemoryStream. Not sure what your function expects, but to stuff a UTF-8 string into it for example: //Act using (var test_Stream = new MemoryStream(Encoding.UTF8.GetBytes(“whatever”))) { var result = imp.Import(test_Stream); // Assert Assert.IsTrue(result); } EDIT: If you need an Excel file, and you are unable to read files from disk, could you add an … Read more

How to read file content into istringstream?

std::ifstream has a method rdbuf(), that returns a pointer to a filebuf. You can then “push” this filebuf into your stringstream: #include <fstream> #include <sstream> int main() { std::ifstream file( “myFile” ); if ( file ) { std::stringstream buffer; buffer << file.rdbuf(); file.close(); // operations on the buffer… } } EDIT: As Martin York remarks … Read more

NodeJS: What’s the difference between a Duplex stream and a Transform stream?

A Duplex stream can be thought of a readable stream with a writable stream. Both are independent and each have separate internal buffer. The reads and writes events happen independently. Duplex Stream ——————| Read <—– External Source You ——————| Write —–> External Sink ——————| You don’t get what you write. It is sent to another … Read more

Not buffered http.ResponseWritter in Golang

As implied in the documentation, some ResponseWriter may implement the Flusher interface. This means you can do something like this : func handle(res http.ResponseWriter, req *http.Request) { fmt.Fprintf(res, “sending first line of data”) if f, ok := res.(http.Flusher); ok { f.Flush() } else { log.Println(“Damn, no flush”); } sleep(10) //not real code fmt.Fprintf(res, “sending second … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)