dylex / zip-stream

Haskell ZIP archive streaming processing using conduit
BSD 3-Clause "New" or "Revised" License
7 stars 8 forks source link

Don't set compression flag for known 0-byte files #9

Closed Philonous closed 5 years ago

Philonous commented 5 years ago

The compression flag was already unset for 0-byte ByteStrings, however, for empty files it would still be set even when a size was explicitly set in the ZipEntry. This patch fixes that.

It should actually be possible to determine whether a Conduit stream is empty by demanding the first (non-empty) fragment and creating a new conduit that first yields the retrieved fragment and then continues with the old conduit as usual. This should not impact the memory usage as the fragment would be fetched immediately after anyway. I have not tried to implement that yet, though.

dylex commented 5 years ago

This is great, thanks! Out of curiosity, does compressed 0-byte data break something or just waste space with the compression header?

I think there's a Data.Conduit.Combinators.peekE function that would make the other part easier. You're certainly welcome to look into that.

Let me know if you'd like a new hackage release with this as it is.

Philonous commented 5 years ago

Windows file explorer apparently can't handle 0-byte files with compression enabled, otherwise I wouldn't care ;) I'm working around the issue by stat-ing the file (necessary to set the size anyway) and then passing an empty ByteString instead of a Conduit, so it's not terribly urgent.