Permalink
Browse files

add resize example

  • Loading branch information...
tj committed Jul 14, 2012
1 parent 84951a7 commit 4a1651cca85d43c3e79bfe783a6b9044d0ca44eb
View
@@ -1,2 +1,3 @@
node_modules
testing
+.DS_Store
@@ -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);
+ });
+});
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
@@ -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);
+ });
+});

0 comments on commit 4a1651c

Please sign in to comment.