Hi Alex, On Sep 27, 2011, at 1:16 PM, Alex Boisvert wrote:
> On Tue, Sep 27, 2011 at 10:02 AM, Dieter Vrancken < > [email protected]> wrote: > >> We are filtering our resources with settings from the profile and it is >> great! The problem is that one of our devs added a png image to the >> resources directory. As the filter tries to interpolate variables into this >> binary file, it fails miserably. Are we not supposed to put binary files in >> our resources? That would be unfortunate! >> > > Hi Dieter, > > Yeah, that's a problem. You can circumvent the problem by monkey-patching > the Mapper class, e.g., > > https://gist.github.com/1245748 > > module Buildr > class Filter > class Mapper > > alias_method :transform_old, :transform > > BINARY_FILES = [ '*.png', '*.gif' ] > > def is_binary?(content, path) > BINARY_FILES.any? { |glob| File.fnmatch(glob, path) } > end > > def transform(content, path = nil) > return content if is_binary?(content, path) > transform_old(content, path) > end > end > end > end > > I'll fix this in Buildr so the next release doesn't apply filter mappings > willy-nelly on binary files. (BTW, do you have any suggestion on good > binary content detection?) I looked into this when I was working on jartools[1]. I don't know how good it is, but I ended up using the technique that diff uses[2] -- if there are any null bytes, it's binary; otherwise text. Rhett [1]: https://github.com/NUBIC/jartools [2]: http://www.gnu.org/s/hello/manual/diff/Binary.html > > Thanks for bringing this up. > > alex
