Skip to content

Instantly share code, notes, and snippets.

@TwP
Forked from copiousfreetime/concat.rb
Created September 9, 2011 16:23
Show Gist options
  • Save TwP/1206661 to your computer and use it in GitHub Desktop.
Save TwP/1206661 to your computer and use it in GitHub Desktop.
#!/usr/bin/env
# Possibly one of the faster wasy to concatenate two files in ruby.
# Another way might be to use the lower level IO#sysread, IO#syswrite methods
# I think the main benefit in this case is the reusing of the String instance as
# the buffer.
dest = ARGV.shift
src = ARGV.shift
bufsize = File.stat(dest).blksize || 8192
buffer = String.new
File.open(dest, 'a') { |d|
File.open(src, 'r') { |r|
while b = r.read(bufsize, buffer)
d.syswrite b
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment