You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -137,11 +137,12 @@ if err != nil {
137
137
Have an input stream with unknown contents? No problem, archiver can identify it for you. It will try matching based on filename and/or the header (which peeks at the stream):
138
138
139
139
```go
140
-
format, err:= archiver.Identify("filename.tar.zst", input)
140
+
format, input, err:= archiver.Identify("filename.tar.zst", input)
141
141
if err != nil {
142
142
return err
143
143
}
144
-
// you can now type-assert format to whatever you need
144
+
// you can now type-assert format to whatever you need;
145
+
// be sure to use returned stream to re-read consumed bytes during Identify()
145
146
146
147
// want to extract something?
147
148
ifex, ok:= format.(archiver.Extractor); ok {
@@ -160,6 +161,8 @@ if decom, ok := format.(archiver.Decompressor); ok {
160
161
}
161
162
```
162
163
164
+
`Identify()` works by reading an arbitrary number of bytes from the beginning of the stream (just enough to check for file headers). It buffers them and returns a new reader that lets you re-read them anew.
0 commit comments