Skip to content

Commit 0cffe96

Browse files
committed
added: FrameworkImage supports Buffer
1 parent a6babaa commit 0cffe96

4 files changed

Lines changed: 41 additions & 18 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Framework supports a backward compatibility.
3838
- added: framework.on('init')
3939
- added: framework.merge('/merge.js', '/js/file1.js', '/js/file2.js')
4040
- added: framework supports X-Forwarded-Protocol header
41+
- added: FrameworkImage supports buffer
4142

4243
- updated: (IMPORTANT) all models are loaded after is the framework loaded
4344
- updated: Utils.request(), timeout is possible to add as cookie, headers or encoding

image.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ Image.prototype.save = function(filename, callback) {
196196
callback(null, filename);
197197
});
198198

199-
if (self.currentStream)
200-
self.currentStream.pipe(cmd.stdin);
199+
if (self.currentStream) {
200+
if (self.currentStream instanceof Buffer)
201+
cmd.stdin.end(self.currentStream);
202+
else
203+
self.currentStream.pipe(cmd.stdin);
204+
}
201205

202206
return self;
203207
};
@@ -232,8 +236,12 @@ Image.prototype.pipe = function(stream, type, options) {
232236
cmd.on('error', stream.emit.bind(stream, 'error'));
233237
cmd.stdout.pipe(stream, options);
234238

235-
if (self.currentStream)
236-
self.currentStream.pipe(cmd.stdin);
239+
if (self.currentStream) {
240+
if (self.currentStream instanceof Buffer)
241+
cmd.stdin.end(self.currentStream);
242+
else
243+
self.currentStream.pipe(cmd.stdin);
244+
}
237245

238246
return self;
239247
};
@@ -256,8 +264,12 @@ Image.prototype.stream = function(type) {
256264

257265
var cmd = spawn(self.isIM ? 'convert' : 'gm', self.arg(self.filename === null ? '-' : self.filename, (type ? type + ':' : '') + '-'));
258266

259-
if (self.currentStream)
260-
self.currentStream.pipe(cmd.stdin);
267+
if (self.currentStream) {
268+
if (self.currentStream instanceof Buffer)
269+
cmd.stdin.end(self.currentStream);
270+
else
271+
self.currentStream.pipe(cmd.stdin);
272+
}
261273

262274
return cmd.stdout;
263275
};

minify/total.js/image.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-framework-test.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
var framework = require('../index');
2-
var url = 'http://127.0.0.1:8001/';
1+
// var framework = require('../index');
2+
// var url = 'http://127.0.0.1:8001/';
3+
//
4+
// var mem = require('memwatch');
5+
//
6+
// mem.on('leak', function(info) {
7+
// console.log('LEAK ->', info);
8+
// });
9+
//
10+
// mem.on('stats', function(info) {
11+
// console.log('STATS ->', JSON.stringify(info));
12+
// });
13+
//
14+
// framework.http('debug', { port: 8001 });
315

4-
var mem = require('memwatch');
16+
var Image = require('../image');
17+
var fs = require('fs');
18+
var buffer = fs.readFileSync('/users/petersirka/desktop/picture.png');
519

6-
mem.on('leak', function(info) {
7-
console.log('LEAK ->', info);
8-
});
20+
var img = Image.load(buffer);
921

10-
mem.on('stats', function(info) {
11-
console.log('STATS ->', JSON.stringify(info));
12-
});
13-
14-
framework.http('debug', { port: 8001 });
22+
img.resize('50%');
23+
img.output('png');
24+
img.save('/users/petersirka/desktop/picture-resize.png');

0 commit comments

Comments
 (0)