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 | e97d0b7764969431782fadf6c074ee867583efa0 (patch) | |
tree | 420352459630960c50ccb5b38698b611255480c3 | |
parent | fa1f7befa95c930a68f4b7ace4a4e6e1dd221773 (diff) | |
download | ruby-e97d0b7764969431782fadf6c074ee867583efa0.tar.gz |
* lib/ftool.rb (BUFSIZE): tuning, set buffer length to 8192.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/ftools.rb | 37 |
2 files changed, 15 insertions, 26 deletions
@@ -1,3 +1,7 @@ +Thu Jun 20 17:10:27 2002 WATANABE Hirofumi <eban@ruby-lang.org> + + * lib/ftool.rb (BUFSIZE): tuning, set buffer length to 8192. + Wed Jun 19 14:46:18 2002 WATANABE Hirofumi <eban@ruby-lang.org> * ext/extmk.rb, lib/mkmf.rb (xsystem): open the log file if xsystem diff --git a/lib/ftools.rb b/lib/ftools.rb index 6bf23fe7e5..1b06bf5ecb 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 |