[Pkg-javascript-commits] [node-cp] 01/02: New upstream version 0.2.0

Julien Puydt julien.puydt at laposte.net
Fri Aug 25 10:44:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-cp.

commit 78679cd728117437c46b6aa0c598cd447d9baaa0
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Wed Aug 23 16:41:39 2017 +0200

    New upstream version 0.2.0
---
 .gitignore          |  2 ++
 .npmignore          |  1 +
 .travis.yml         |  5 +++
 History.md          | 22 +++++++++++++
 Makefile            | 28 ++++++++++++++++
 Readme.md           | 41 ++++++++++++++++++++++++
 index.js            | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json        | 33 +++++++++++++++++++
 test/fixtures/a.txt |  1 +
 test/fixtures/b.txt |  1 +
 test/fixtures/c.txt |  1 +
 test/index.js       | 70 ++++++++++++++++++++++++++++++++++++++++
 12 files changed, 297 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3091757
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+node_modules
+coverage
\ No newline at end of file
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1 @@
+test
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..150d49d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+  - "0.10"
+  - "0.11"
+script: "make test"
\ No newline at end of file
diff --git a/History.md b/History.md
new file mode 100644
index 0000000..87b64b5
--- /dev/null
+++ b/History.md
@@ -0,0 +1,22 @@
+
+0.2.0 / 2014-11-14
+==================
+
+  * .travis: Remove node 0.8
+  * index: Add `yield cp(src, dst)` support (closes #4)
+  * Readme: Rename to match conventions
+  * Readme: Add `yield` dox
+  * History: Rename/rewrite to match conventions
+  * Makefile: Refactor to use istanbul for coverage
+  * Add travis
+
+0.1.1 / 2013-07-08
+==================
+
+* added test-coverage reporting
+* explicitly destroying streams to prevent erroneously leaving one open on error
+
+0.1.0 / 2013-07-01
+==================
+
+* initial release, support `cp(src, dest, cb)` and `cp.sync(src, dest)`
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..db313a1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+
+BIN := node_modules/.bin
+NODE ?= node
+SRC = $(wildcard *.js)
+TEST = $(wildcard test/*.js)
+
+test: NODE=$(BIN)/gnode
+test: node_modules
+	$(NODE) $(BIN)/_mocha \
+	  --reporter spec \
+	  --require co-mocha \
+	  $(NODE_FLAGS)
+
+# coverage only available on 0.11
+coverage: node_modules $(SRC) $(TEST)
+	$(NODE) --harmony-generators $(BIN)/istanbul cover \
+	  $(BIN)/_mocha -- \
+	    --require co-mocha \
+	    --reporter spec
+
+node_modules: package.json
+	@npm install
+	@touch $@
+
+clean:
+	@rm -rf coverage test/fixtures/*copy*
+
+.PHONY: test clean
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..a44c0ce
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,41 @@
+
+# cp
+
+`cp` for node
+
+Really simple, straight-forward copying of files.
+
+## API
+
+### `cp(src, dest, cb)` / `yield cp(src, dest)`
+
+Copy file `src` to `dest`
+
+### `cp.sync(src, dest)`
+
+Synchronously copy file `src` to `dest`
+
+## License 
+
+(The MIT License)
+
+Copyright (c) 2013 Stephen Mathieson <me at stephenmathieson.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..1f97d96
--- /dev/null
+++ b/index.js
@@ -0,0 +1,92 @@
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs');
+try { fs = require('graceful-fs'); } catch (e) {}
+
+/**
+ * Magic number.
+ */
+
+var MAX_BUFFER = 1024;
+
+/**
+ * Export `cp`.
+ */
+
+exports = module.exports = cp;
+
+/**
+ * Export `sync`.
+ */
+
+exports.sync = sync;
+
+/**
+ * Copy `src` to `dest`, invoking `cb(err)` when done.
+ *
+ * @param {String} src
+ * @param {String} dest
+ * @param {Function} [cb]
+ * @api public
+ */
+
+function cp(src, dest, cb) {
+  // yield support
+  if ('function' != typeof cb) return thunk;
+
+  var complete = false;
+  var read = fs.createReadStream(src);
+  var write = fs.createWriteStream(dest);
+
+  write.on('error', done);
+  write.on('close', done);
+  read.on('error', done);
+  read.pipe(write);
+
+  // done callback
+  function done(err) {
+    if (!complete) {
+      complete = true;
+      read.destroy();
+      write.destroy();
+      cb(err);
+    }
+  }
+
+  // thunk-ified
+  function thunk(done) {
+    cp(src, dest, done);
+  }
+}
+
+/**
+ * Synchronously copy file `src` to `dest`
+ *
+ * @param {String} src
+ * @param {String} dest
+ * @api public
+ */
+
+function sync(src, dest) {
+  if (!fs.existsSync(src)) {
+    throw new Error('no such file or directory: ' + src);
+  }
+
+  var buffer = new Buffer(MAX_BUFFER);
+  var bytesRead = MAX_BUFFER;
+  var pos = 0;
+  var read = fs.openSync(src, 'r');
+  var write = fs.openSync(dest, 'w');
+
+  while (MAX_BUFFER == bytesRead) {
+    bytesRead = fs.readSync(read, buffer, 0, MAX_BUFFER, pos);
+    fs.writeSync(write, buffer, 0, bytesRead);
+    pos += bytesRead;
+  }
+
+  fs.closeSync(read);
+  fs.closeSync(write);
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..c3a833d
--- /dev/null
+++ b/package.json
@@ -0,0 +1,33 @@
+{
+  "name": "cp",
+  "version": "0.2.0",
+  "description": "cp for node",
+  "keywords": [
+    "fs",
+    "copy",
+    "cp"
+  ],
+  "author": "Stephen Mathieson <me at stephenmathieson.com>",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/stephenmathieson/node-cp.git"
+  },
+  "devDependencies": {
+    "co-mocha": "^1.0.3",
+    "glob": "~3.2.1",
+    "gnode": "^0.1.0",
+    "istanbul": "git://github.com/gotwarlost/istanbul#c6f8fc8b102cfa4e4455d6a165485b38cb58160c",
+    "mocha": "^2.0.1"
+  },
+  "main": "index",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/stephenmathieson/node-cp/issues"
+  },
+  "directories": {
+    "test": "test"
+  },
+  "scripts": {
+    "test": "make test"
+  }
+}
diff --git a/test/fixtures/a.txt b/test/fixtures/a.txt
new file mode 100644
index 0000000..2e65efe
--- /dev/null
+++ b/test/fixtures/a.txt
@@ -0,0 +1 @@
+a
\ No newline at end of file
diff --git a/test/fixtures/b.txt b/test/fixtures/b.txt
new file mode 100644
index 0000000..63d8dbd
--- /dev/null
+++ b/test/fixtures/b.txt
@@ -0,0 +1 @@
+b
\ No newline at end of file
diff --git a/test/fixtures/c.txt b/test/fixtures/c.txt
new file mode 100644
index 0000000..3410062
--- /dev/null
+++ b/test/fixtures/c.txt
@@ -0,0 +1 @@
+c
\ No newline at end of file
diff --git a/test/index.js b/test/index.js
new file mode 100644
index 0000000..3f948ca
--- /dev/null
+++ b/test/index.js
@@ -0,0 +1,70 @@
+
+var assert = require('assert');
+var path = require('path');
+var fixture = path.join.bind(path, __dirname, 'fixtures');
+var fs = require('fs');
+var glob = require('glob').sync;
+var cp = require('..');
+
+describe('cp(src, dest, fn)', function() {
+  beforeEach(cleanup);
+
+  it('should copy files', function(done) {
+    cp(fixture('a.txt'), fixture('a-copy.txt'), function(err) {
+      if (err) return done(err);
+      var str = fs.readFileSync(fixture('a-copy.txt'), 'utf8');
+      assert('a' == str);
+      done();
+    });
+  });
+
+  it('should propagate fs errors', function(done) {
+    cp(fixture('nope'), fixture('nope copy'), function(err) {
+      assert(err);
+      done();
+    });
+  });
+});
+
+describe('yield cp(src, dest)', function() {
+  beforeEach(cleanup);
+
+  it('should copy files', function*() {
+    yield cp(fixture('a.txt'), fixture('a-copy.txt'));
+    var str = fs.readFileSync(fixture('a-copy.txt'), 'utf8');
+    assert('a' == str);
+  });
+
+  it('should propagate fs errors', function*() {
+    var err;
+    try {
+      yield cp(fixture('nope'), fixture('nope copy'));
+    } catch (e) {
+      err = e;
+    }
+    assert(err);
+  });
+});
+
+describe('cp.sync(src, dest)', function() {
+  beforeEach(cleanup);
+
+  it('should copy files', function() {
+    cp.sync(fixture('a.txt'), fixture('a-copy.txt'));
+    var str = fs.readFileSync(fixture('a-copy.txt'), 'utf8');
+    assert('a' == str);
+  });
+
+  it('should propagate fs errors', function() {
+    assert.throws(function() {
+      cp.sync(fixture('nope'), fixture('nope copy'));
+    });
+  });
+});
+
+function cleanup() {
+  var files = glob(fixture('*copy*'));
+  for (var i = files.length - 1; i >= 0; i--) {
+    fs.unlinkSync(files[i]);
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-cp.git



More information about the Pkg-javascript-commits mailing list