-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from runk/gzip-format-check
A check for gzip format
- Loading branch information
Showing
5 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function(buf) { | ||
if (!buf || buf.length < 3) { | ||
return false; | ||
} | ||
|
||
return buf[0] === 0x1f && buf[1] === 0x8b && buf[2] === 0x08; | ||
}; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var isGzip = require('../lib/is-gzip'); | ||
|
||
describe('lib/is-gzip', function() { | ||
it('should return false for short buffers', function() { | ||
assert.equal(isGzip(new Buffer([1, 2])), false); | ||
}); | ||
|
||
it('should return false for string buffer', function() { | ||
assert.equal(isGzip(new Buffer('kraken')), false); | ||
}); | ||
|
||
it('should return false for string buffer', function() { | ||
// gzipped "kraken" string | ||
// shell: `echo "kraken" | gzip | base64` | ||
var buffer = new Buffer('H4sIAGBDv1gAA8suSsxOzeMCAKjj9U8HAAAA', 'base64'); | ||
assert.equal(isGzip(buffer), true); | ||
}); | ||
}); |