Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add resize example

  • Loading branch information...
commit 4a1651cca85d43c3e79bfe783a6b9044d0ca44eb 1 parent 84951a7
@tj authored
View
1  .gitignore
@@ -1,2 +1,3 @@
node_modules
testing
+.DS_Store
View
25 examples/workers/consumer.js
@@ -0,0 +1,25 @@
+
+// $ npm install resize
+
+var ss = require('../..')
+ , sock = ss.socket('pull')
+ , sink = ss.socket('push')
+ , resize = require('resize')
+ , fs = require('fs');
+
+// connect
+
+sock.connect(3000);
+sink.connect(3001);
+console.log('consumer connected to 3000');
+
+// resize
+
+sock.on('message', function(img){
+ console.log('resizing %dkb image', img.length / 1024 | 0);
+ resize(img, 50, 50, function(err, buf){
+ if (err) throw err;
+ // ^ dont do this
+ sink.send(buf);
+ });
+});
View
BIN  examples/workers/images/one.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  examples/workers/images/three.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  examples/workers/images/two.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
26 examples/workers/producer.js
@@ -0,0 +1,26 @@
+
+var ss = require('../..')
+ , sock = ss.socket('push')
+ , fs = require('fs')
+ , read = fs.readFileSync;
+
+// images
+
+var images = [
+ read(__dirname + '/images/one.jpeg'),
+ read(__dirname + '/images/two.jpeg'),
+ read(__dirname + '/images/three.jpeg'),
+];
+
+// bind
+
+sock.bind(3000);
+console.log('producer bound to 3000');
+
+// send random images
+
+setInterval(function(){
+ var img = images[Math.random() * images.length | 0];
+ console.log('sending %dkb image', img.length / 1024 | 0);
+ sock.send(img);
+}, 200);
View
21 examples/workers/sink.js
@@ -0,0 +1,21 @@
+
+var ss = require('../..')
+ , sock = ss.socket('pull')
+ , fs = require('fs');
+
+// bind
+
+sock.bind(3001);
+console.log('sink bound to 3001');
+
+// save images
+
+sock.on('message', function(img){
+ console.log(img);
+ var path = '/tmp/' + (Math.random() * 0xffffff | 0);
+ fs.writeFile(path, img, function(err){
+ if (err) throw err;
+ // ^ dont do this
+ console.log('saved %s', path);
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.