[Pkg-javascript-commits] [node-crc32-stream] 01/07: Imported Upstream version 0.2.0

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sat Jun 28 22:22:59 UTC 2014


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

andrewrk-guest pushed a commit to branch master
in repository node-crc32-stream.

commit 55dc1d0cb34f1cfce58b2314ae708342ad65517e
Author: Andrew Kelley <superjoe30 at gmail.com>
Date:   Sat Jun 28 21:48:16 2014 +0000

    Imported Upstream version 0.2.0
---
 .gitignore            |  3 ++
 .travis.yml           |  4 +++
 CHANGELOG             | 18 ++++++++++
 CONTRIBUTING.md       | 14 ++++++++
 LICENSE-MIT           | 22 ++++++++++++
 README.md             | 59 ++++++++++++++++++++++++++++++++
 lib/crc32-stream.js   | 44 ++++++++++++++++++++++++
 package.json          | 44 ++++++++++++++++++++++++
 test/checksum.js      | 39 +++++++++++++++++++++
 test/helpers/index.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 340 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c766b8b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+npm-debug.log
+node_modules/
+tmp/
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..2ca91f2
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - "0.10"
+  - "0.8"
\ No newline at end of file
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..b87f161
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,18 @@
+v0.2.0:
+  date: 2014-05-03
+  changes:
+    - add size method to return raw size of data passed-through.
+v0.1.2:
+  date: 2014-04-18
+  changes:
+    - always use readable-stream for consistency.
+    - use crc32.unsigned to get digest.
+v0.1.1:
+  date: 2014-03-30
+  changes:
+    - gracefully handle "no data" scenario.
+    - trim down deps.
+v0.1.0:
+  date: 2014-03-30
+  changes:
+    - initial release.
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..1fa92d4
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,14 @@
+## Contributing
+
+#### Code Style Guide
+
+* code should be indented with 2 spaces
+* single quotes should be used where feasible
+* commas should be followed by a single space (function params, etc)
+* variable declaration should include `var`, [no multiple declarations](http://benalman.com/news/2012/05/multiple-var-statements-javascript/)
+
+#### Tests
+
+* tests should be added to the nodeunit configs in `test/`
+* tests can be run with `npm test`
+* see existing tests for guidance
\ No newline at end of file
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644
index 0000000..56420a6
--- /dev/null
+++ b/LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2014 Chris Talkington, contributors.
+
+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/README.md b/README.md
new file mode 100644
index 0000000..9ad3e1e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,59 @@
+# crc32-stream v0.2.0 [![Build Status](https://travis-ci.org/ctalkington/node-crc32-stream.svg?branch=master)](https://travis-ci.org/ctalkington/node-crc32-stream)
+
+crc32-stream is a streaming CRC32 checksumer. It uses [buffer-crc32](https://www.npmjs.org/package/buffer-crc32) behind the scenes to reliably handle binary data and fancy character sets. Data is passed through untouched.
+
+[![NPM](https://nodei.co/npm/crc32-stream.png)](https://nodei.co/npm/crc32-stream/)
+
+### Install
+
+```bash
+npm install crc32-stream --save
+```
+
+You can also use `npm install https://github.com/ctalkington/node-crc32-stream/archive/master.tar.gz` to test upcoming versions.
+
+### Usage
+
+```js
+var CRC32Stream = require('crc32-stream');
+
+var source = fs.createReadStream('file.txt');
+var checksum = new CRC32Stream();
+
+checksum.on('end', function(err) {
+  // do something with checksum.digest() here
+});
+
+// either pipe it
+source.pipe(checksum);
+
+// or write it
+checksum.write('string');
+checksum.end();
+```
+
+### Instance API
+
+Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) methods.
+
+#### digest()
+
+Returns the checksum digest in unsigned form.
+
+#### hex()
+
+Returns the hexadecimal representation of the checksum digest. (ie E81722F0)
+
+#### size()
+
+Returns the raw size/length of passed-through data.
+
+### Instance Options
+
+Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) options.
+
+## Things of Interest
+
+- [Changelog](https://github.com/ctalkington/node-crc32-stream/releases)
+- [Contributing](https://github.com/ctalkington/node-crc32-stream/blob/master/CONTRIBUTING.md)
+- [MIT License](https://github.com/ctalkington/node-crc32-stream/blob/master/LICENSE-MIT)
\ No newline at end of file
diff --git a/lib/crc32-stream.js b/lib/crc32-stream.js
new file mode 100644
index 0000000..f13aa68
--- /dev/null
+++ b/lib/crc32-stream.js
@@ -0,0 +1,44 @@
+/**
+ * node-crc32-stream
+ *
+ * Copyright (c) 2014 Chris Talkington, contributors.
+ * Licensed under the MIT license.
+ * https://github.com/ctalkington/node-crc32-stream/blob/master/LICENSE-MIT
+ */
+var inherits = require('util').inherits;
+var Transform = require('readable-stream').Transform;
+
+var crc32 = require('buffer-crc32');
+
+function CRC32Stream(options) {
+  Transform.call(this, options);
+  this.checksum = new Buffer(4);
+  this.checksum.writeInt32BE(0, 0);
+
+  this.rawSize = 0;
+}
+
+inherits(CRC32Stream, Transform);
+
+CRC32Stream.prototype._transform = function(chunk, encoding, callback) {
+  if (chunk) {
+    this.checksum = crc32(chunk, this.checksum);
+    this.rawSize += chunk.length;
+  }
+
+  callback(null, chunk);
+};
+
+CRC32Stream.prototype.digest = function() {
+  return crc32.unsigned(0, this.checksum);
+};
+
+CRC32Stream.prototype.hex = function() {
+  return this.digest().toString(16).toUpperCase();
+};
+
+CRC32Stream.prototype.size = function() {
+  return this.rawSize;
+};
+
+module.exports = CRC32Stream;
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..2bbe5dd
--- /dev/null
+++ b/package.json
@@ -0,0 +1,44 @@
+{
+  "name": "crc32-stream",
+  "version": "0.2.0",
+  "description": "a streaming CRC32 checksumer",
+  "homepage": "https://github.com/ctalkington/node-crc32-stream",
+  "author": {
+    "name": "Chris Talkington",
+    "url": "http://christalkington.com/"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/ctalkington/node-crc32-stream.git"
+  },
+  "bugs": {
+    "url": "https://github.com/ctalkington/node-crc32-stream/issues"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/ctalkington/node-crc32-stream/blob/master/LICENSE-MIT"
+    }
+  ],
+  "main": "lib/crc32-stream.js",
+  "engines": {
+    "node": ">= 0.8.0"
+  },
+  "scripts": {
+    "test": "mocha --reporter dot"
+  },
+  "dependencies": {
+    "readable-stream": "~1.0.24",
+    "buffer-crc32": "~0.2.1"
+  },
+  "devDependencies": {
+    "chai": "~1.8.1",
+    "mocha": "~1.16.0"
+  },
+  "keywords": [
+    "crc32-stream",
+    "crc32",
+    "stream",
+    "checksum"
+  ]
+}
\ No newline at end of file
diff --git a/test/checksum.js b/test/checksum.js
new file mode 100644
index 0000000..967fa92
--- /dev/null
+++ b/test/checksum.js
@@ -0,0 +1,39 @@
+/*global before,describe,it */
+var assert = require('chai').assert;
+
+var helpers = require('./helpers');
+var BinaryStream = helpers.BinaryStream;
+var DeadEndStream = helpers.DeadEndStream;
+
+var CRC32Stream = require('../lib/crc32-stream.js');
+
+describe('CRC32Stream', function() {
+  it('should checksum data while passing through data', function(done) {
+    var binary = new BinaryStream(1024 * 16);
+    var checksum = new CRC32Stream();
+    var deadend = new DeadEndStream();
+
+    checksum.on('end', function() {
+      assert.equal(checksum.digest(), 3893830384);
+      assert.equal(checksum.hex(), 'E81722F0');
+      assert.equal(checksum.size(), 16384);
+      done();
+    });
+
+    checksum.pipe(deadend);
+    binary.pipe(checksum);
+  });
+
+  it('should gracefully handle having no data chunks passed to it', function(done) {
+    var checksum = new CRC32Stream();
+    var deadend = new DeadEndStream();
+
+    checksum.on('end', function() {
+      assert.equal(checksum.digest(), 0);
+      done();
+    });
+
+    checksum.pipe(deadend);
+    checksum.end();
+  });
+});
\ No newline at end of file
diff --git a/test/helpers/index.js b/test/helpers/index.js
new file mode 100644
index 0000000..84f4ded
--- /dev/null
+++ b/test/helpers/index.js
@@ -0,0 +1,93 @@
+var crypto = require('crypto');
+var fs = require('fs');
+var inherits = require('util').inherits;
+
+var Stream = require('stream').Stream;
+var Readable = require('readable-stream').Readable;
+var Writable = require('readable-stream').Writable;
+
+function adjustDateByOffset(d, offset) {
+  d = (d instanceof Date) ? d : new Date();
+
+  if (offset >= 1) {
+    d.setMinutes(d.getMinutes() - offset);
+  } else {
+    d.setMinutes(d.getMinutes() + Math.abs(offset));
+  }
+
+  return d;
+}
+
+module.exports.adjustDateByOffset = adjustDateByOffset;
+
+function binaryBuffer(n) {
+  var buffer = new Buffer(n);
+
+  for (var i = 0; i < n; i++) {
+    buffer.writeUInt8(i&255, i);
+  }
+
+  return buffer;
+}
+
+module.exports.binaryBuffer = binaryBuffer;
+
+function BinaryStream(size, options) {
+  Readable.call(this, options);
+
+  var buf = new Buffer(size);
+
+  for (var i = 0; i < size; i++) {
+    buf.writeUInt8(i&255, i);
+  }
+
+  this.push(buf);
+  this.push(null);
+}
+
+inherits(BinaryStream, Readable);
+
+BinaryStream.prototype._read = function(size) {};
+
+module.exports.BinaryStream = BinaryStream;
+
+function DeadEndStream(options) {
+  Writable.call(this, options);
+}
+
+inherits(DeadEndStream, Writable);
+
+DeadEndStream.prototype._write = function(chuck, encoding, callback) {
+  callback();
+};
+
+module.exports.DeadEndStream = DeadEndStream;
+
+function fileBuffer(filepath) {
+  return fs.readFileSync(filepath);
+}
+
+module.exports.fileBuffer = fileBuffer;
+
+function WriteHashStream(path, options) {
+  fs.WriteStream.call(this, path, options);
+
+  this.hash = crypto.createHash('sha1');
+  this.digest = null;
+
+  this.on('close', function() {
+    this.digest = this.hash.digest('hex');
+  });
+}
+
+inherits(WriteHashStream, fs.WriteStream);
+
+WriteHashStream.prototype.write = function(chunk) {
+  if (chunk) {
+    this.hash.update(chunk);
+  }
+
+  return fs.WriteStream.prototype.write.call(this, chunk);
+};
+
+module.exports.WriteHashStream = WriteHashStream;
\ No newline at end of file

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



More information about the Pkg-javascript-commits mailing list