Comments (4)
file
reader stream is stateful and when the stream is consumed, data will be drained. The simplest way to solve this is to reinitialize the reader by opening the file again or, alternatively, writing head data back into the reader buffer via file.WriteAt(head, 0)
from filetype.
@h2non I tried to write it, but it didn't work
from filetype.
You could just close the first file reader stream, then open it again and read the full content.
from filetype.
@helloshaohua
There are two options:
- As your case is a file you can use
Seek
method_, err := file.Seek(0, io.SeekStart)
. Next read start from zero; - For any case is to use
[]byte
buffer, like you did, but also chain readers withio.MultiReader
file, err := os.Open("../../test/assets/HgWFAEPozfVdcst")
// ...
head := make([]byte, 262)
_, _ = io.ReadFull(file, head)
match, err := filetype.Match(head)
// ...
reader := io.MultiReader(bytes.NewBuffer(head), file)
// ...
err = o.client.PutObject("HgWFAEPozfVdcst", reader) // put io.MultiReader
p.s. Don't forget to close the file
/reader
from filetype.
Related Issues (20)
- m4a mime type HOT 2
- tar file not being recognized HOT 1
- fatal error: magic.h: No such file or directory
- directory not recognized HOT 1
- ASCII Text Files Starting With Letters "BM" Are Treated As BMP Image Files
- Why ppt matcher return false for a ppt file
- Add MPEG-TS video format
- docx file is recognised as zip file HOT 3
- Easy way to recognize new formats?
- Many mime types not recognized
- deb file incorrectly matching to ar HOT 1
- Cannot install package HOT 1
- password producted file file match not working
- How do I get the http streaming file type HOT 1
- run all the time with no result, if the file name is 'console'
- xlsx类型的文件解析为zip格式
- avif file detecting is not stable
- Release tags
- Need to .ai file format, adobe illustrator HOT 1
- There is a problem with avif format check
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filetype.