https://github.com/fanweixiao/oppressor
streaming http compression response negotiator
https://github.com/fanweixiao/oppressor
Last synced: 2 months ago
JSON representation
streaming http compression response negotiator
- Host: GitHub
- URL: https://github.com/fanweixiao/oppressor
- Owner: fanweixiao
- License: other
- Created: 2012-12-17T07:06:24.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-08-29T03:04:58.000Z (almost 13 years ago)
- Last Synced: 2025-02-14T13:47:39.191Z (4 months ago)
- Language: JavaScript
- Size: 74.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.markdown
- License: LICENSE
Awesome Lists containing this project
README
# oppressor
streaming http compression response negotiator
[](http://travis-ci.org/substack/oppressor)
# example
You can use plain old streams:
``` js
var oppressor = require('oppressor');
var fs = require('fs');
var http = require('http');var server = http.createServer(function (req, res) {
fs.createReadStream(__dirname + '/data.txt')
.pipe(oppressor(req))
.pipe(res)
;
});
server.listen(8000);
```or you can use fancy streaming static file server modules like
[filed](http://github.com/mikeal/filed) that set handy things like etag,
last-modified, and content-type headers for you:(For now you'll need to use [my fork](https://github.com/substack/filed)
until [this pull request](https://github.com/mikeal/filed/pull/25) gets merged.)``` js
var oppressor = require('oppressor');
var filed = require('filed');
var http = require('http');var server = http.createServer(function (req, res) {
filed(__dirname + '/data.txt')
.pipe(oppressor(req))
.pipe(res)
;
});
server.listen(8000);
```# methods
``` js
var oppressor = require('oppressor')
```## var stream = oppressor(req)
Return a [duplex stream](https://github.com/substack/stream-handbook#duplex)
that will be compressed with gzip, deflate, or no compression depending on the
accept-encoding headers sent.oppressor will emulate calls to http.ServerResponse methods like `writeHead()`
so that modules like [filed](http://github.com/mikeal/filed) that expect to be
piped directly to the response object will work.# install
With [npm](https://npmjs.org) do:
```
npm install oppressor
```# license
MIT