Download File to server from URL

Since PHP 5.1.0, file_put_contents() supports writing piece-by-piece by passing a stream-handle as the $data parameter: file_put_contents(“Tmpfile.zip”, fopen(“http://someurl/file.zip”, ‘r’)); From the manual: If data [that is the second argument] is a stream resource, the remaining buffer of that stream will be copied to the specified file. This is similar with using stream_copy_to_stream(). (Thanks Hakre.)

How do I save a stream to a file in C#?

As highlighted by Tilendor in Jon Skeet’s answer, streams have a CopyTo method since .NET 4. var fileStream = File.Create(“C:\\Path\\To\\File”); myOtherObject.InputStream.Seek(0, SeekOrigin.Begin); myOtherObject.InputStream.CopyTo(fileStream); fileStream.Close(); Or with the using syntax: using (var fileStream = File.Create(“C:\\Path\\To\\File”)) { myOtherObject.InputStream.Seek(0, SeekOrigin.Begin); myOtherObject.InputStream.CopyTo(fileStream); }

Easy way to write contents of a Java InputStream to an OutputStream

Java 9 Since Java 9, InputStream provides a method called transferTo with the following signature: public long transferTo(OutputStream out) throws IOException As the documentation states, transferTo will: Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. On return, this input stream … Read more

Java Process with Input/Output Stream

Firstly, I would recommend replacing the line Process process = Runtime.getRuntime ().exec (“/bin/bash”); with the lines ProcessBuilder builder = new ProcessBuilder(“/bin/bash”); builder.redirectErrorStream(true); Process process = builder.start(); ProcessBuilder is new in Java 5 and makes running external processes easier. In my opinion, its most significant improvement over Runtime.getRuntime().exec() is that it allows you to redirect the … Read more

Download large file in python with requests

With the following streaming code, the Python memory usage is restricted regardless of the size of the downloaded file: def download_file(url): local_filename = url.split(“https://stackoverflow.com/”)[-1] # NOTE the stream=True parameter below with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, ‘wb’) as f: for chunk in r.iter_content(chunk_size=8192): # If you have chunk encoded response uncomment if # … Read more