Skip to content
This repository
Browse code

Merge pull request #1426 from piscis/master

change crc generator because of license issue
  • Loading branch information...
commit 763be5e6310c086a87ac4aecf8f8880864b32e8a 2 parents 5cf29a3 + 18a3cc0
TJ Holowaychuk authored
6  lib/utils.js
@@ -4,7 +4,7 @@
4 4
  */
5 5
 
6 6
 var mime = require('connect').mime
7  
-  , crc = require('crc');
  7
+  , crc32 = require('buffer-crc32');
8 8
 
9 9
 /**
10 10
  * Return ETag for `body`.
@@ -15,9 +15,7 @@ var mime = require('connect').mime
15 15
  */
16 16
 
17 17
 exports.etag = function(body){
18  
-  return '"' + (Buffer.isBuffer(body)
19  
-    ? crc.buffer.crc32(body)
20  
-    : crc.crc32(body)) + '"';
  18
+  return '"' + crc32.signed(body) + '"';
21 19
 };
22 20
 
23 21
 /**
2  package.json
@@ -15,7 +15,7 @@
15 15
     "range-parser": "0.0.4",
16 16
     "mkdirp": "0.3.3",
17 17
     "cookie": "0.0.4",
18  
-    "crc": "0.2.0",
  18
+    "buffer-crc32": "0.1.1",
19 19
     "fresh": "0.1.0",
20 20
     "methods": "0.0.1",
21 21
     "send": "0.1.0",
20  test/utils.js
@@ -2,6 +2,26 @@
2 2
 var utils = require('../lib/utils')
3 3
   , assert = require('assert');
4 4
 
  5
+describe('utils.etag(body)', function(){
  6
+
  7
+  var str = 'Hello CRC';
  8
+  var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';
  9
+  
  10
+  it('should support strings', function(){
  11
+    utils.etag(str).should.eql('"-2034458343"');
  12
+  })
  13
+
  14
+  it('should support utf8 strings', function(){
  15
+    utils.etag(strUTF8).should.eql('"1395090196"');
  16
+  })
  17
+
  18
+  it('should support buffer', function(){
  19
+    utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');
  20
+    utils.etag(new Buffer(str)).should.eql('"-2034458343"');
  21
+  })
  22
+
  23
+})
  24
+
5 25
 describe('utils.isAbsolute()', function(){
6 26
   it('should support windows', function(){
7 27
     assert(utils.isAbsolute('c:\\'));

0 notes on commit 763be5e

Please sign in to comment.
Something went wrong with that request. Please try again.