grunt-contrib-copy
grunt-contrib-copy copied to clipboard
Corrupted copy (v0.7.0)
Hi,
I have an issue when copy a lot of files (images, pdf, etc) from one directory to another one. In a destination folder all these files is corrupted.
I tried to use both noProcess
and processContentExclude
options but it brought no results.
My copy task config looks like this:
copy: {
assets_images: {
options: {
noProcess: ['**/*.{png,gif,jpg,ico,pdf}']
},
expand: true,
cwd: 'static/images/',
src: '**',
dest: 'dist/assets/images/'
},
assets_data: {
options: {
noProcess: ['**/*.{png,gif,jpg,ico,pdf}']
},
expand: true,
cwd: 'static/data/',
src: '**',
dest: 'dist/assets/data/'
}
}
_UPDATE:_
I did some investigations and found out that binary code of the png files in the source and destionation folders are differ.
I suspect that copy task process files using wrong encoding (by default it is utf8). As I understand it process them as a binary files and utf8 is not a correct encoding in this case.
What would you recomend to do for fix this issue?
i've run into the same issue with png and ico files. Any update on this?
Same issue here...
Well, after debugging this for an hour, here's what I got.
First misconception: there is no »per file pair options« – so this
copy: {
assets_images: {
options: { ... }, // <= anything you set here is ignored and never processed
expand: true,
...
}
}
is ignored. Silently.
That's because copyOptions
is set here: https://github.com/gruntjs/grunt-contrib-copy/blob/master/tasks/copy.js#L30 and used here: https://github.com/gruntjs/grunt-contrib-copy/blob/master/tasks/copy.js#L99, while options
set inside a file pair object are never touched, read or handled.
You may, however, use the global options for this:
copy: {
options: {
noProcess: ['**/*.{png,gif,jpg,ico,pdf}']
},
assets_images: {
expand: true,
...
}
}
This works – I just wrestled with this myself.
Still, your example is somewhat misleading. Where's your process option? It, too, can only be defined in the global options and without it there's no processing and/or corruption happening (letting me believe that some other task is handling your binary data as strings). Despite this inconsistency I will leave my explanation above so the unlucky soul stumbling upon this when processing binary and string data in a copy operation doesn't have to spend an hour debugging this.
One last tidbit: this plugin is using grunt.file.copy(src, dst, options)
– its documentation is here: http://gruntjs.com/api/grunt.file#grunt.file.copy. The corruption can be avoided when setting encoding: null,
in the options then the process function is handed a Buffer instead of a string.