Giter Site home page Giter Site logo

dcopy's Introduction

dcopy Build and test

A tiny (241B to 339B) utility to copy items recursively

This is a Promise-based, cross-platform utility that recursively copy files and directories.

Notice: Node v16.7.0 added an experimental fs.cp and fs.cpSync.

Install

$ npm install --save @tatchi/dcopy

Modes

There are two "versions" of dcopy available:

"async"

Size (gzip): 340 bytes
> Availability: CommonJS, ES Module

This is the primary/default mode. It makes use of async/await and util.promisify.

"sync"

Size (gzip): 241 bytes
> Availability: CommonJS, ES Module

This is the opt-in mode, ideal for scenarios where async usage cannot be supported.
In order to use it, simply make the following changes:

-import { dcopy } from 'dcopy';
+import { dcopy } from 'dcopy/sync';

Usage

import { dcopy } from "dcopy";

// Async/await
try {
  await dcopy("./foobar", "./foobar_copy");
} catch (err) {
  //
}

// Promise
dcopy("./foobar", "./foobar_copy")
  .then(() => {
    //
  })
  .catch((err) => {
    //
  });

// Sync
import { dcopy } from "dcopy/sync";
dcopy("./foobar", "./foobar_copy");

API

dcopy(srcPath, dstPath)

Returns: Promise<void>

Returns a Promise that resolves when all the files/folders have been copied to the destination.

Important:
The sync and async versions share the same API.
The only difference is that sync is not Promise-based.

srcPath

Type: String

The filepath to copy from โ€“ may be a file or a directory.

dstPath

Type: String

The filepath to copy to.

Acknowledgments

This library is heavily inspired from and reuses lots of lukeed's work. Thanks for his amazing work ๐Ÿ˜

dcopy's People

Contributors

tatchi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.