Permalink
Browse files

First commit for quiver-compress.

  • Loading branch information...
0 parents commit 077b3135118f9809e307128aeaae153562b20502 Soares Chen committed Apr 14, 2013
Showing with 118 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 Makefile
  3. +5 −0 README.md
  4. +18 −0 lib/compress.js
  5. +35 −0 package.json
  6. +54 −0 test/test.js
@@ -0,0 +1 @@
+node_modules/
@@ -0,0 +1,5 @@
+
+test:
+ @NODE_ENV=test ./node_modules/.bin/mocha;
+
+.PHONY: test
@@ -0,0 +1,5 @@
+
+quiver-compress
+==============
+
+Accept a stream and return a compressed/decompressed stream
@@ -0,0 +1,18 @@
+
+var zlib = require('zlib')
+var streamConvert = require('quiver-stream-convert')
+
+var gzipTransformer = streamConvert.createStreamTransformer('Gzip', zlib.gzip)
+var gunzipTransformer = streamConvert.createStreamTransformer('Gunzip', zlib.gunzip)
+var deflateTransformer = streamConvert.createStreamTransformer('Deflate', zlib.deflate)
+var inflateTransformer = streamConvert.createStreamTransformer('Inflate', zlib.inflate)
+
+module.exports = {
+ streamToGzipStream: gzipTransformer.streamToGzipStream,
+ streamableToGzipStream: gzipTransformer.streamableToGzipStream,
+ gzipStreamToStream: gunzipTransformer.streamToGunzipStream,
+
+ streamToDeflateStream: deflateTransformer.streamToDeflateStream,
+ streamableToDeflateStream: deflateTransformer.streamableToDeflateStream,
+ deflateStreamToStream: inflateTransformer.streamToInflateStream
+}
@@ -0,0 +1,35 @@
+{
+ "author": {
+ "name": "Soares Chen",
+ "email": "soares.chen@gmail.com",
+ "url": "http://soareschen.com"
+ },
+ "name": "quiver-compress",
+ "desription": "Accept a stream and return a compressed/decompressed stream",
+ "version": "0.0.1",
+ "homepage": "https://github.com/quiverjs/compress",
+ "repository": {
+ "url": "git@github.com:quiverjs/compress.git"
+ },
+ "dependencies": {
+ "quiver-stream-convert": ">=0.0.4"
+ },
+ "devDependencies": {
+ "quiver-file-stream": ">=0.0.1",
+ "quiver-pipe-stream": ">=0.0.1",
+ "mocha": ">=1.8.1",
+ "should": ">=1.2.2"
+ },
+ "bugs": {
+ "url": "https://github.com/quiverjs/compress/issues",
+ "email": "quiverjs@soareschen.com"
+ },
+ "licenses": {
+ "type": "MIT",
+ "url": "https://raw.github.com/quiverjs/license/master/LICENSE"
+ },
+ "main": "./lib/compress",
+ "scripts": {
+ "test": "make test"
+ }
+}
@@ -0,0 +1,54 @@
+
+var pathUtil = require('path')
+var should = require('should')
+var compress = require('../lib/compress')
+var fileStream = require('quiver-file-stream')
+var pipeStream = require('quiver-pipe-stream').pipeStream
+var streamConvert = require('quiver-stream-convert')
+
+var testReadFile = pathUtil.join(__dirname, '../lib/compress.js')
+var testWriteFile = pathUtil.join(__dirname, 'test-compressed.gz')
+var compareWriteFile = pathUtil.join(__dirname, 'compare-compressed.gz')
+
+describe('compress manual test', function() {
+ it('should save a compressed file', function(callback) {
+ fileStream.createFileReadStream(testReadFile, function(err, readStream) {
+ if(err) throw err
+
+ fileStream.createFileWriteStream(testWriteFile, function(err, writeStream) {
+ if(err) throw err
+
+ compress.streamToGzipStream(readStream, function(err, transformedStream) {
+ if(err) throw err
+
+ pipeStream(transformedStream, writeStream, callback)
+ })
+ })
+ })
+ })
+
+ it('should save a decompressed file', function(callback) {
+ fileStream.createFileReadStream(testReadFile, function(err, originalStream) {
+ if(err) throw err
+
+ streamConvert.streamToText(originalStream, function(err, originalText) {
+ if(err) throw err
+
+ fileStream.createFileReadStream(compareWriteFile, function(err, compressedStream) {
+ if(err) throw err
+
+ compress.gzipStreamToStream(compressedStream, function(err, decompressedStream) {
+ if(err) throw err
+
+ streamConvert.streamToText(decompressedStream, function(err, decompressedText) {
+ if(err) throw err
+
+ decompressedText.should.equal(originalText)
+ callback()
+ })
+ })
+ })
+ })
+ })
+ })
+})

0 comments on commit 077b313

Please sign in to comment.