diff options
author | eban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-06-20 08:21:00 +0000 |
---|---|---|
committer | eban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-06-20 08:21:00 +0000 |
commit | 9765ed088be7e3835b815a14bca31b1fe339414b (patch) | |
tree | 420352459630960c50ccb5b38698b611255480c3 /lib/ftools.rb | |
parent | bd80904effeb9e82582677cfc22c7b5b571af831 (diff) | |
download | ruby-9765ed088be7e3835b815a14bca31b1fe339414b.tar.gz ruby-9765ed088be7e3835b815a14bca31b1fe339414b.tar.xz ruby-9765ed088be7e3835b815a14bca31b1fe339414b.zip |
* lib/ftool.rb (BUFSIZE): tuning, set buffer length to 8192.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/ftools.rb')
-rw-r--r-- | lib/ftools.rb | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/lib/ftools.rb b/lib/ftools.rb index 6bf23fe7e..1b06bf5ec 100644 --- a/lib/ftools.rb +++ b/lib/ftools.rb @@ -1,6 +1,6 @@ class << File - TOO_BIG = 1024 * 1024 * 2 # 2MB + BUFSIZE = 8 * 1024 def catname from, to if FileTest.directory? to @@ -15,28 +15,16 @@ class << File def syscopy from, to to = catname(from, to) - fsize = size(from) - fsize = 1024 if fsize < 512 - fsize = TOO_BIG if fsize > TOO_BIG - fmode = stat(from).mode tpath = to not_exist = !exist?(tpath) - from = open(from, "r") - from.binmode - to = open(to, "w") - to.binmode + from = open(from, "rb") + to = open(to, "wb") begin while true - r = from.sysread(fsize) - rsize = r.size - w = 0 - while w < rsize - t = to.syswrite(r[w, rsize - w]) - w += t - end + to.syswrite from.sysread(BUFSIZE) end rescue EOFError ret = true @@ -63,7 +51,7 @@ class << File to = catname(from, to) $stderr.print from, " -> ", to, "\n" if verbose - if RUBY_PLATFORM =~ /djgpp|cygwin|mswin32|bccwin32/ and FileTest.file? to + if RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ and FileTest.file? to unlink to end fstat = stat(from) @@ -92,25 +80,22 @@ class << File def compare from, to, verbose = false $stderr.print from, " <=> ", to, "\n" if verbose - fsize = size(from) - fsize = 1024 if fsize < 512 - fsize = TOO_BIG if fsize > TOO_BIG - from = open(from, "r") - from.binmode - to = open(to, "r") - to.binmode + from = open(from, "rb") + to = open(to, "rb") ret = false fr = tr = '' + return false if from.stat.size != to.stat.size + begin while fr == tr - fr = from.read(fsize) + fr = from.read(BUFSIZE) if fr tr = to.read(fr.size) else - ret = to.read(fsize) + ret = to.read(BUFSIZE) ret = !ret || ret.length == 0 break end |