Skip to content

Commit

Permalink
readme: Update example for Identify()
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Mar 17, 2022
1 parent 4fc750e commit dda6eaa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -137,11 +137,12 @@ if err != nil {
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):

```go
format, err := archiver.Identify("filename.tar.zst", input)
format, input, err := archiver.Identify("filename.tar.zst", input)
if err != nil {
return err
}
// you can now type-assert format to whatever you need
// you can now type-assert format to whatever you need;
// be sure to use returned stream to re-read consumed bytes during Identify()

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

`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.

### Virtual file systems

This is my favorite feature.
Expand Down

0 comments on commit dda6eaa

Please sign in to comment.