Skip to content

Commit

Permalink
Merge pull request #1426 from piscis/master
Browse files Browse the repository at this point in the history
change crc generator because of license issue
  • Loading branch information
tj committed Nov 21, 2012
2 parents 5cf29a3 + 18a3cc0 commit 763be5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/utils.js
Expand Up @@ -4,7 +4,7 @@
*/

var mime = require('connect').mime
, crc = require('crc');
, crc32 = require('buffer-crc32');

/**
* Return ETag for `body`.
Expand All @@ -15,9 +15,7 @@ var mime = require('connect').mime
*/

exports.etag = function(body){
return '"' + (Buffer.isBuffer(body)
? crc.buffer.crc32(body)
: crc.crc32(body)) + '"';
return '"' + crc32.signed(body) + '"';
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -15,7 +15,7 @@
"range-parser": "0.0.4",
"mkdirp": "0.3.3",
"cookie": "0.0.4",
"crc": "0.2.0",
"buffer-crc32": "0.1.1",
"fresh": "0.1.0",
"methods": "0.0.1",
"send": "0.1.0",
Expand Down
20 changes: 20 additions & 0 deletions test/utils.js
Expand Up @@ -2,6 +2,26 @@
var utils = require('../lib/utils')
, assert = require('assert');

describe('utils.etag(body)', function(){

var str = 'Hello CRC';
var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';

it('should support strings', function(){
utils.etag(str).should.eql('"-2034458343"');
})

it('should support utf8 strings', function(){
utils.etag(strUTF8).should.eql('"1395090196"');
})

it('should support buffer', function(){
utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');
utils.etag(new Buffer(str)).should.eql('"-2034458343"');
})

})

describe('utils.isAbsolute()', function(){
it('should support windows', function(){
assert(utils.isAbsolute('c:\\'));
Expand Down

0 comments on commit 763be5e

Please sign in to comment.