[Pkg-javascript-commits] [node-file-sync-cmp] 01/04: Imported Upstream version 0.1.1

Ross Gammon ross-guest at moszumanska.debian.org
Tue Dec 20 18:42:06 UTC 2016


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

ross-guest pushed a commit to branch master
in repository node-file-sync-cmp.

commit 1c52780e0e0a1b6500136dd8eb243d0590d33687
Author: Ross Gammon <rossgammon at mail.dk>
Date:   Tue Dec 20 17:36:40 2016 +0100

    Imported Upstream version 0.1.1
---
 .eslintrc      | 33 +++++++++++++++++++++++++++++++++
 .gitignore     |  2 ++
 .travis.yml    |  1 +
 LICENSE        | 22 ++++++++++++++++++++++
 README.md      | 14 ++++++++++++++
 index.js       | 37 +++++++++++++++++++++++++++++++++++++
 package.json   | 32 ++++++++++++++++++++++++++++++++
 test/.eslintrc |  7 +++++++
 test/test.js   | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 202 insertions(+)

diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..1255f3d
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,33 @@
+# -*- yaml -*-
+---
+env:
+  node: true
+
+rules:
+  quotes:
+  - 2
+  - single
+  - avoid-escape
+  global-strict:
+  - 2
+  - always
+  space-in-brackets: 2
+  space-in-parens: 2
+  space-after-keywords:
+  - 2
+  - always
+  - { checkFunctionKeyword: true }
+  space-before-blocks: 2
+  space-unary-ops: 2
+  brace-style: 2
+  comma-style: 2
+  func-style:
+  - 2
+  - declaration
+  no-lonely-if: 2
+  no-trailing-spaces: 2
+  no-multiple-empty-lines: 2
+  max-len: 2
+  padded-blocks:
+  - 2
+  - never
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..50a0c39
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*~
+node_modules/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..587bd3e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1 @@
+language: node_js
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..dd78f7e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Martin Geisler
+
+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.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3ab9201
--- /dev/null
+++ b/README.md
@@ -0,0 +1,14 @@
+file-sync-cmp
+=============
+
+[![Build Status](https://travis-ci.org/mgeisler/file-sync-cmp.svg?branch=master)](https://travis-ci.org/mgeisler/file-sync-cmp)
+
+Synchronous file comparison for Node.js.
+
+
+Release History
+---------------
+
+* 0.1.1 (2015-02-22): Close file descriptors after comparison.
+
+* 0.1.0 (2014-12-14): First public release.
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..f386657
--- /dev/null
+++ b/index.js
@@ -0,0 +1,37 @@
+'use strict';
+
+var fs = require('fs');
+
+var BUF_SIZE = 16 * 1024;
+
+/* Compare two files by content. */
+function equalFiles(pathA, pathB) {
+    var statA = fs.lstatSync(pathA);
+    var statB = fs.lstatSync(pathB);
+    if (statA.size !== statB.size) {
+        return false;
+    }
+    var fdA = fs.openSync(pathA, 'r');
+    var fdB = fs.openSync(pathB, 'r');
+    var bufA = new Buffer(BUF_SIZE);
+    var bufB = new Buffer(BUF_SIZE);
+    var readA = 1;
+    var readB = 1;
+    while (readA > 0) {
+        readA = fs.readSync(fdA, bufA, 0, bufA.length, null);
+        readB = fs.readSync(fdB, bufB, 0, bufB.length, null);
+        if (readA !== readB) {
+            return false;
+        }
+        for (var i = 0; i < readA; i++) {
+            if (bufA[i] !== bufB[i]) {
+                return false;
+            }
+        }
+    }
+    fs.closeSync(fdA);
+    fs.closeSync(fdB);
+    return true;
+}
+
+module.exports.equalFiles = equalFiles;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e62279b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,32 @@
+{
+  "name": "file-sync-cmp",
+  "version": "0.1.1",
+  "description": "Synchronous file comparison",
+  "main": "index.js",
+  "homepage": "https://github.com/mgeisler/file-sync-cmp/",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/mgeisler/file-sync-cmp.git"
+  },
+  "keywords": [
+    "comparison"
+  ],
+  "author": {
+    "name": "Martin Geisler",
+    "email": "martin at geisler.net",
+    "url": "http://geisler.net/"
+  },
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/mgeisler/file-sync-cmp/issues"
+  },
+  "devDependencies": {
+    "eslint": "0.10.1",
+    "mocha": "2.0.1",
+    "q": "1.1.2",
+    "tmp": "0.0.24"
+  },
+  "scripts": {
+    "test": "eslint . && mocha"
+  }
+}
diff --git a/test/.eslintrc b/test/.eslintrc
new file mode 100644
index 0000000..efac5a1
--- /dev/null
+++ b/test/.eslintrc
@@ -0,0 +1,7 @@
+# -*- yaml -*-
+---
+globals:
+  afterEach: false
+  beforeEach: false
+  describe: false
+  it: false
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..9a71723
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,54 @@
+'use strict';
+
+var fileSyncCmp = require('../');
+
+var assert = require('assert');
+var fs = require('fs');
+
+var tmp = require('tmp');
+tmp.setGracefulCleanup();
+
+var Q = require('q');
+
+var fsWrite = Q.nfbind(fs.write);
+var tmpFile = Q.nfbind(tmp.file);
+
+function write (fd, buf) {
+    return fsWrite(fd, buf, 0, buf.length, null);
+}
+
+
+describe('equalFiles', function () {
+    var pathA, pathB;
+    var fdA, fdB;
+
+    beforeEach(function () {
+        return Q.all([tmpFile(), tmpFile()]).spread(function (a, b) {
+            pathA = a[0];
+            pathB = b[0];
+            fdA = a[1];
+            fdB = b[1];
+        });
+    });
+
+    it('should handle empty files', function () {
+        assert(fileSyncCmp.equalFiles(pathA, pathB));
+    });
+
+    it('should handle equal content', function () {
+        var buf = new Buffer('File content\n');
+        var writes = [write(fdA, buf), write(fdB, buf)];
+        return Q.all(writes).then(function () {
+            assert(fileSyncCmp.equalFiles(pathA, pathB));
+        });
+    });
+
+    it('should handle non-equal content', function () {
+        var bufA = new Buffer('Some text\n');
+        var bufB = new Buffer('Other text\n');
+        var writes = [write(fdA, bufA), write(fdB, bufB)];
+        return Q.all(writes).then(function () {
+            assert(!fileSyncCmp.equalFiles(pathA, pathB));
+        });
+    });
+});

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



More information about the Pkg-javascript-commits mailing list