Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File transformers cannot handle binary files #105

Closed
teehemkay opened this issue Apr 4, 2016 · 6 comments
Closed

File transformers cannot handle binary files #105

teehemkay opened this issue Apr 4, 2016 · 6 comments

Comments

@teehemkay
Copy link

Gobble provides the contents of an individual file to a file transformer plugin as text input.
This prevents a file transformer from handling binary files which is quite a bummer.

For example, since image optimisation can be quite onerous in terms of performance, a file transformer for image optimisation could be more performant than a directory transformer thanks to caching.

@teehemkay teehemkay changed the title File transformer cannot handle binary files File transformers cannot handle binary files Apr 4, 2016
@Rich-Harris
Copy link
Contributor

Thanks – this is fixed in 0.11.2. Use sourceEncoding: null, like so:

function myPlugin ( inputBuffer ) {
  return doSomethingWith( inputBuffer );
}

myPlugin.defaults = {
  sourceEncoding: null
};

@teehemkay
Copy link
Author

👍

@teehemkay
Copy link
Author

teehemkay commented Apr 29, 2016

Unless I'm mistaken, file transformers cannot be async, right?

If that's the case, it's quite unfortunate because it means that one has to chose between async or caching but can't have both?

For example: I want to have a gobble plugin for imagemin. Since optimizing is onerous and a 1-to-1 op, I'd rather use a file transform.

But imagemin processors are async so it's a no go 😞

@IvanSanchez
Copy link
Member

I guess it should be possible for Gobble to detect when a file transformer returns an instance of Promise and wait for it?

@teehemkay
Copy link
Author

Ideally yes. And also maybe use the number of arguments trick (like for the directory transformer) so that one can use a callback instead of returning a promise.

But for the moment, it seems that gobble just assumes that the returned value is the transformed contents (see

result = options.fn.call( context, data, transformOptions );
)

@teehemkay
Copy link
Author

I've opened a feature request (#112) for this btw.
So maybe it's better to further discuss this there 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants