Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created March 22, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryochack/f20d4de00324838e685dd7d6795fd0fa to your computer and use it in GitHub Desktop.
Save ryochack/f20d4de00324838e685dd7d6795fd0fa to your computer and use it in GitHub Desktop.
use std::io::{self, Read, Write};
use std::fs::File;
fn copy(reader: &mut Read, writer: &mut Write) {
const BUFFER_SIZE: usize = 32 * 1024;
let mut buf = [0u8; BUFFER_SIZE];
while let Ok(n) = reader.read(&mut buf) {
if n == 0 {
break;
}
let _ = writer.write(&buf[..n]);
}
}
fn main() {
let r = io::stdin();
let mut reader = r.lock();
let mut writer = File::create("temp.txt").unwrap();
copy(&mut reader, &mut writer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment