Permalink
Browse files

added files

  • Loading branch information...
0 parents commit 0f4dfa43a7538a5a0ccfaf3e5f0d90e35b746403 @matomesc matomesc committed Nov 2, 2011
Showing with 154 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +29 −0 Readme.md
  5. +2 −0 index.js
  6. +1 −0 lib/files/hello-client.txt
  7. +1 −0 lib/files/hello-server.txt
  8. +99 −0 lib/node-rsync.js
  9. +10 −0 package.json
  10. 0 test/tests.js
@@ -0,0 +1,3 @@
+.DS_Store
+node_modules
+*.sock
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,29 @@
+
+# node-rsync
+
+ rsync implemented in node over http
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 Mihai Tomescu <matomesc@gmail.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.
@@ -0,0 +1,2 @@
+
+module.exports = require('./lib/node-rsync');
@@ -0,0 +1 @@
+Hello, world!
@@ -0,0 +1 @@
+Hello, world!
@@ -0,0 +1,99 @@
+/*!
+ * node-rsync
+ * Copyright(c) 2011 Mihai Tomescu <matomesc@gmail.com>
+ * MIT Licensed
+ */
+
+var crypto = require('crypto')
+ , fs = require('fs');
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.0.1';
+
+var chunkSize = 2;
+
+var rsync = {
+ //
+ // chunk a file
+ //
+ chunk: function (path, callback) {
+ var chunks = [];
+
+ // read raw file
+ fs.readFile(path, function (err, data) {
+ if (err) {
+ return callback(err);
+ }
+
+ var input = data
+ , length = data.length;
+
+ if (length <= chunkSize) {
+ chunks.push(input);
+
+ return callback(null, {
+ num: chunks.length
+ , chunks: chunks
+ });
+ }
+
+ var start = 0
+ , end = chunkSize;
+
+ while (start < length) {
+ var chunk = input.slice(start, end);
+ chunks.push(chunk);
+
+ // update slice indices
+ start += chunkSize;
+ end = (end + chunkSize) < length ? end + chunkSize : length;
+ }
+
+ return callback(null, {
+ num: chunks.length
+ , chunks: chunks
+ });
+
+ });
+ },
+ //
+ // calculates two checksums for each chunk:
+ // weak - adler-32 (32 bit)
+ // strong - md5 (128 bit)
+ //
+ checksum: function (chunkData, callback) {
+ var num = chunkData.num
+ , chunks = chunkData.chunks;
+
+ chunks.forEach(function (chunk) {
+ var sum = {
+ weak: rollingChecksum(chunk)
+ , strong:
+ }
+ var weakSum = rollingChecksum(chunk);
+ console.log('chunk: %s\n sum: %d', chunk, sum);
+ });
+ }
+};
+
+function rollingChecksum (chunk) {
+ var M = 1 << 16
+ , length = chunk.length
+ , A = 0
+ , B = 0
+ , i;
+
+ for (i = 0; i < length; i++) {
+ A += chunk[i];
+ B += A;
+ }
+
+ return A + M * B;
+}
+
+rsync.chunk('./files/hello-client.txt', function (err, chunkData) {
+ rsync.checksum(chunkData);
+});
@@ -0,0 +1,10 @@
+{
+ "name": "node-rsync"
+ , "version": "0.0.1"
+ , "description": "rsync implemented in node over http"
+ , "keywords": []
+ , "author": "Mihai Tomescu <matomesc@gmail.com>"
+ , "dependencies": {}
+ , "main": "index"
+ , "engines": { "node": "0.4.x" }
+}
No changes.

0 comments on commit 0f4dfa4

Please sign in to comment.