Writer struct allowing io.Copy or io.TeeReader from a reader #66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
History of this PR:
I was looking to write an
io.Reader
(a file incoming through http multipart) into a file while extracting the MD5 checksum (usingcrypto/md5
)and detect theMIME
type. I came across with this library but I realized I needed to create anio.Writer
struct to wrap this library in order to use it along withio.TeeReader
to perform the three actions in one step.Work done:
I basically created a struct that wraps a buffer which reads the first 8192 bytes and discards the rest by implemented the
io.Writer
. I also added a method that passes the internal buffer into theMatch
function.Also I added a simple test which could be improved.
Things I don't like:
Write
method (which makes the struct coply withio.Writer
interface) could be improved, at least it seems a bit complicated.Anyway, I wanted to know what do you think of this patch. Maybe it is not necessary, maybe is not even a good patch. Here is how I ended up using it.
Hey, thanks for this library. It's really good.