-
-
Save TwP/1206661 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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