gulpjs / gulp

A toolkit to automate & enhance your workflow

Home Page:https://gulpjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v5 gulp.src/dest copies text files 1:1 but breaks binary files

prurigro opened this issue · comments

I'm assuming this isn't another situation where the expected behaviour has changed, apologies if it is!

What were you expecting to happen?

In previous versions of gulp, running gulp.src("input/*").pipe(gulp.dest("public/")); would copy files from input to public without altering them.

What actually happened?

In gulp v5 the above copies text files to the destination correctly, but binary files are altered. They're about twice the size, and seem to be converted to text.

Please give us a sample of your gulpfile

This task is meant to copy fonts from a few locations to a location in the .gitignore - the svg fonts are fine, but the rest are broken.

https://github.com/prurigro/hypothetical/blob/master/gulpfile.js#L290

Terminal output / screenshots

top of the original file:
image

further down in the original file (where the binary data:
image

top of the copied file:
image

further down in the copied file:
image

Please provide the following information:

  • OS & version [e.g. MacOS Catalina 10.15.4]: Archlinux (up-to-date)
  • node version (run node -v): v21.7.1
  • npm version (run npm -v): 10.5.0
  • gulp version (run gulp -v): CLI version: 3.0.0 - Local version: 5.0.0

Thanks for your time!

This is by design and the first breaking change highlighted in our release blog: https://medium.com/gulpjs/announcing-gulp-v5-c67d077dbdb7

Copying files really shouldn't be done with gulp streams, as you are just using them to glob, which doesn't need the overhead of streams. You can just read the directory and copy.

If you still want to take on that overhead, you definitely should not be copying without { read: false } configuration because you are reading all the files into memory to write them back out again. If dest() sees empty contents, it does a 1-1 copy which is way faster.

If you need to read for some reason, you can always set { encoding: false } to ignore all encoding options.

Thanks again for pointing me in the right direction :) It seems like setting { encoding: false } gets me back to where I was with the least friction for now, and I'll look at doing it in a more correct way once the documentation's been updated.

Docs have been updated: https://github.com/gulpjs/gulp/blob/master/docs/api/src.md#options

You need to add { encoding: false } for binary files.