Skip to content

Instantly share code, notes, and snippets.

@copiousfreetime
Created September 9, 2011 16:03
Show Gist options
  • Save copiousfreetime/1206606 to your computer and use it in GitHub Desktop.
Save copiousfreetime/1206606 to your computer and use it in GitHub Desktop.
#!/usr/bin/env
# NOTE, Untested code.
#
# 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
File.open( dest, "a" ) do |d|
File.open( src, "r" ) do |r|
buffer = String.new()
while b = r.read( bufsize, buffer ) do
w.write( b )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment