Sha256: bd881baa92ef7fea151a3df6fda011ace2687ff2d6c4b8596548250f9f33f8f5

Contents?: true

Size: 982 Bytes

Versions: 46

Compression:

Stored size: 982 Bytes

Contents

'use strict'

const fs = require('graceful-fs')

const BUF_LENGTH = 64 * 1024
const _buff = require('../util/buffer')(BUF_LENGTH)

function copyFileSync (srcFile, destFile, options) {
  const overwrite = options.overwrite
  const errorOnExist = options.errorOnExist
  const preserveTimestamps = options.preserveTimestamps

  if (fs.existsSync(destFile)) {
    if (overwrite) {
      fs.unlinkSync(destFile)
    } else if (errorOnExist) {
      throw new Error(`${destFile} already exists`)
    } else return
  }

  const fdr = fs.openSync(srcFile, 'r')
  const stat = fs.fstatSync(fdr)
  const fdw = fs.openSync(destFile, 'w', stat.mode)
  let bytesRead = 1
  let pos = 0

  while (bytesRead > 0) {
    bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
    fs.writeSync(fdw, _buff, 0, bytesRead)
    pos += bytesRead
  }

  if (preserveTimestamps) {
    fs.futimesSync(fdw, stat.atime, stat.mtime)
  }

  fs.closeSync(fdr)
  fs.closeSync(fdw)
}

module.exports = copyFileSync

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
ilog-0.4.1 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
ilog-0.4.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
ilog-0.3.3 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-18.0.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.21.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.20.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.19.1 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.19.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.18.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.17.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.16.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.15.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.14.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.13.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.12.2 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.12.1 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.12.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.11.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.10.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
govuk_publishing_components-17.9.0 node_modules/fs-extra/lib/copy-sync/copy-file-sync.js