marshallpierce / rust-base64

base64, in rust
Apache License 2.0
616 stars 115 forks source link

Calling `EncoderStringWriter::write` successively does not equal `EncoderStringWriter::write_all` #247

Closed nascent-harry closed 1 year ago

nascent-harry commented 1 year ago

The problem

From the docs it seems like using EncoderStringWriter::write incrementally and EncoderStringWriter::write_all once should produce the same result.

This is not the case as seen in the following example:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5ec7ce07f0bd526e7cb8272134eff351

marshallpierce commented 1 year ago

Hm, that doesn't seem great. Thanks for the report; I'll look into it.

marshallpierce commented 1 year ago

The issue is that the third write() call isn't consuming all of the input, which is per the spec. It only consumes the first two bytes. If you call write() again with the remaining un-used input, all is well: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a0770eb15be84f64778143d78e8b500a. I'll also add a test to ensure this works.