fpgaminer / rust-lzma

A Rust crate that provides a simple interface for LZMA compression and decompression.
MIT License
79 stars 14 forks source link

Improve drop implementation to prevent accidental corruption #10

Closed efyang closed 8 years ago

efyang commented 8 years ago

Basically, this PR just forces LzmaWriter to call finish before ending the stream. This prevents any accidental corruptions and makes it much easier to write any structs that might contain it, and makes it behave a bit more like compressors in the flate2 and bzip2 libraries.

fpgaminer commented 8 years ago

Hey, thank you for this pull request! Sorry I did not get a chance to take a look at it sooner.

The reason I wasn't calling finish in drop is because finish returns an error and drop has no way to propagate that error to the library's user. It allows the user to write code that compiles and runs correctly, but which isn't actually correct, because it won't handle all error scenarios. That's not very Rust-ic I think.

efyang commented 8 years ago

Ah ok, makes sense.