Skip to content

Commit

Permalink
Merge pull request #553 from wontem/fs-readSync-throws-error
Browse files Browse the repository at this point in the history
copySync, moveSync: remove extra step in reading loop
  • Loading branch information
jprichardson committed Mar 17, 2018
2 parents a0d44c1 + 7e2aba0 commit b7aa7e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/copy-sync/copy-sync.js
Expand Up @@ -91,11 +91,10 @@ function copyFileFallback (srcStat, src, dest, opts) {

const fdr = fs.openSync(src, 'r')
const fdw = fs.openSync(dest, 'w', srcStat.mode)
let bytesRead = 1
let pos = 0

while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
while (pos < srcStat.size) {
const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
fs.writeSync(fdw, _buff, 0, bytesRead)
pos += bytesRead
}
Expand Down
5 changes: 2 additions & 3 deletions lib/move-sync/index.js
Expand Up @@ -68,11 +68,10 @@ function moveFileSyncAcrossDevice (src, dest, overwrite) {
const fdr = fs.openSync(src, 'r')
const stat = fs.fstatSync(fdr)
const fdw = fs.openSync(dest, flags, stat.mode)
let bytesRead = 1
let pos = 0

while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
while (pos < stat.size) {
const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
fs.writeSync(fdw, _buff, 0, bytesRead)
pos += bytesRead
}
Expand Down

0 comments on commit b7aa7e3

Please sign in to comment.