jstransformers / jstransformer

Normalize the API of any JSTransformer.
http://npm.im/jstransformer
MIT License
152 stars 12 forks source link

Buffers #92

Open RobLoach opened 9 years ago

RobLoach commented 9 years ago

Work with a buffer rather than string?

https://nodejs.org/api/buffer.html

tunnckoCore commented 9 years ago

Why?

RobLoach commented 9 years ago

To do things like compress image file buffers with imagemin.

tunnckoCore commented 9 years ago

Hm. Can you give example how you see the things? Let say, how you would use jstransfomer-imagemin for example?

I think we now can do it

var imagemin = require('jstransformer')(require('jstransformer-imagemin'))

imagemin.renderAsync('images/foo.png', {
  plugins: [require('gulp-rename')('bar.png')]
}).then()
// => [{path: 'images/bar.png', contents: <Buffer 89 50 4e ...>}, ...]

im not sure

TimothyGu commented 9 years ago

I'm also not sure about this. JSTransformer's APIs are designed with string rendering in mind. Binary blobs are, at the current stage, abusing the APIs a little bit.

RobLoach commented 9 years ago

I enjoy abusing APIs :smiling_imp:

var imagemin = require('jstransformer')(require('jstransformer-imagemin'))

imagemin.renderFileAsync('images/foo.png').then(function (result) {
  result.body
  // => <Buffer 89 50 4e ...>
})

Perhaps just allowing the use of Buffers? Maybe introduce a .renderBuffer()?