Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1426 from piscis/master

change crc generator because of license issue
  • Loading branch information...
commit 763be5e6310c086a87ac4aecf8f8880864b32e8a 2 parents 5cf29a3 + 18a3cc0
@tj tj authored
Showing with 23 additions and 5 deletions.
  1. +2 −4 lib/utils.js
  2. +1 −1  package.json
  3. +20 −0 test/utils.js
View
6 lib/utils.js
@@ -4,7 +4,7 @@
*/
var mime = require('connect').mime
- , crc = require('crc');
+ , crc32 = require('buffer-crc32');
/**
* Return ETag for `body`.
@@ -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) + '"';
};
/**
View
2  package.json
@@ -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",
View
20 test/utils.js
@@ -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:\\'));
Please sign in to comment.
Something went wrong with that request. Please try again.