-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for io.Writer #480
Comments
You can achieve something similar by using a byte buffer, io.TeeReader, and io.MultiReader. The code would look something like this: dstW, _ := os.CreateFile("foo.txt")
header := bytes.NewBuffer(nil)
mtype, _ := mimetype.DetectReader(io.TeeReader(src, header))
src = io.MultiReader(header, src)
// src now contains the complete, original data. There is an example in docs. Let me know if this solves the problem. |
I was talking about writing, not reading. Very different situation with less options to be creative. My main point being there should be something built-in for streams, that's all. |
Sorry, I don't see what's missing for streams. I think my suggestion covers your requirement of no seeks and copying the readily available data to the destination file. In any case, a Feel free to explain the shortcomings of current situation and I will re-open the issue. |
I could really use implementation allowing me to detect mime type of incoming data, like when a file is being uploaded so that I do not have to then rewind the file and process it again with DetectReader.
So the mime writer should simply keep witting into internal buffer until some sane limit or until it can detect the mime type. After that it should be just NOOP. This could be then used with io.MultiWritter where I could write the incoming data into a file on the disk but also detect the mime type along the way since I already have access to all the bytes.
Something like:
The text was updated successfully, but these errors were encountered: