Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit dda6eaa

Browse files
committed
readme: Update example for Identify()
1 parent 4fc750e commit dda6eaa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ if err != nil {
137137
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):
138138

139139
```go
140-
format, err := archiver.Identify("filename.tar.zst", input)
140+
format, input, err := archiver.Identify("filename.tar.zst", input)
141141
if err != nil {
142142
return err
143143
}
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()
145146

146147
// want to extract something?
147148
if ex, ok := format.(archiver.Extractor); ok {
@@ -160,6 +161,8 @@ if decom, ok := format.(archiver.Decompressor); ok {
160161
}
161162
```
162163

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.
165+
163166
### Virtual file systems
164167

165168
This is my favorite feature.

0 commit comments

Comments
 (0)