"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/fs-extra/lib/copy-sync/copy-file-sync.js" (11 Apr 2017, 882 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var fs = require('graceful-fs')
    2 
    3 var BUF_LENGTH = 64 * 1024
    4 var _buff = new Buffer(BUF_LENGTH)
    5 
    6 function copyFileSync (srcFile, destFile, options) {
    7   var clobber = options.clobber
    8   var preserveTimestamps = options.preserveTimestamps
    9 
   10   if (fs.existsSync(destFile)) {
   11     if (clobber) {
   12       fs.chmodSync(destFile, parseInt('777', 8))
   13       fs.unlinkSync(destFile)
   14     } else {
   15       throw Error('EEXIST')
   16     }
   17   }
   18 
   19   var fdr = fs.openSync(srcFile, 'r')
   20   var stat = fs.fstatSync(fdr)
   21   var fdw = fs.openSync(destFile, 'w', stat.mode)
   22   var bytesRead = 1
   23   var pos = 0
   24 
   25   while (bytesRead > 0) {
   26     bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
   27     fs.writeSync(fdw, _buff, 0, bytesRead)
   28     pos += bytesRead
   29   }
   30 
   31   if (preserveTimestamps) {
   32     fs.futimesSync(fdw, stat.atime, stat.mtime)
   33   }
   34 
   35   fs.closeSync(fdr)
   36   fs.closeSync(fdw)
   37 }
   38 
   39 module.exports = copyFileSync