Skip to content
Browse files

updated examples and readme

  • Loading branch information...
1 parent 32be149 commit bce0c7deb4e3a3e0bbec0e420eab4a6dfeda589d andris9 committed Nov 23, 2011
Showing with 14 additions and 8 deletions.
  1. +4 −1 README.md
  2. +5 −3 examples/streamClient.js
  3. +5 −4 examples/streamWorker.js
View
5 README.md
@@ -93,7 +93,9 @@ Example:
## Streaming
-Worker and job objects also act as Stream objects (workers are writable and jobs readable streams), so you can stream data with `pipe` from a worker to a client (but not the other way round).
+Worker and job objects also act as Stream objects (workers are writable and jobs readable streams), so you can stream data with `pipe` from a worker to a client (but not the other way round). This is useful for zipping/unzipping etc.
+
+**NB!** Streaming support is experimental, do not send very large files as the data tends to clutter up (workers stream interface lacks support for pausing etc.).
**Streaming worker**
@@ -111,6 +113,7 @@ Worker and job objects also act as Stream objects (workers are writable and jobs
// save incoming stream to file
job.pipe(output);
+
## License
**MIT**
View
8 examples/streamClient.js
@@ -1,11 +1,13 @@
var Gearman = require("../lib/gearman"),
fs = require("fs"),
- gearman = new Gearman(); // defaults to localhost
+ zlib = require("zlib");
-var job = gearman.submitJob("stream", null),
+var gearman = new Gearman(), // defaults to localhost
+ job = gearman.submitJob("stream", null),
output = fs.createWriteStream(__dirname+"/../../wordlist.txt.copy");
-job.pipe(output, {end: false});
+// unpack stream and send to file
+job.pipe(zlib.createGunzip()).pipe(output);
job.on("end", function(){
console.log("transfer ready");
View
9 examples/streamWorker.js
@@ -1,14 +1,15 @@
var Gearman = require("../lib/gearman"),
- fs = require("fs");
+ fs = require("fs"),
+ zlib = require("zlib");
var gearman = new Gearman(); // defaults to localhost
var filepath = __dirname+"/../../wordlist.txt";
gearman.registerWorker("stream", function(payload, worker){
- // pipe stream to worker
- console.log("start transfer");
- fs.createReadStream(filepath).pipe(worker);
+ // pipe stream to gzip and then to worker
+ console.log("start transfer gzipped content");
+ fs.createReadStream(filepath).pipe(zlib.createGzip()).pipe(worker);
});
gearman.on("connect", function(){

0 comments on commit bce0c7d

Please sign in to comment.
Something went wrong with that request. Please try again.