Permalink
Browse files

merge

  • Loading branch information...
2 parents c852693 + 763be5e commit e2ad0d3d6e7cd3d47a81030e01f47d324af4e2bd @tj tj committed Nov 21, 2012
Showing with 25 additions and 7 deletions.
  1. +2 −4 lib/utils.js
  2. +3 −3 package.json
  3. +20 −0 test/utils.js
View
@@ -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
@@ -3,8 +3,8 @@
"description": "Sinatra inspired web development framework",
"version": "3.0.3",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
- "contributors": [
- { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
+ "contributors": [
+ { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
{ "name": "Aaron Heckmann", "email": "aaron.heckmann+github@gmail.com" },
{ "name": "Ciaran Jessup", "email": "ciaranj@gmail.com" },
{ "name": "Guillermo Rauch", "email": "rauchg@gmail.com" }
@@ -15,7 +15,7 @@
"range-parser": "0.0.4",
"mkdirp": "0.3.3",
"cookie": "0.0.5",
- "crc": "0.2.0",
+ "buffer-crc32": "0.1.1",
"fresh": "0.1.0",
"methods": "0.0.1",
"send": "0.1.0",
View
@@ -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:\\'));

0 comments on commit e2ad0d3

Please sign in to comment.