From dda6eaa0eeb34e0ad7f85a7d41aac54dd9e108bf Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 17 Mar 2022 16:14:09 -0600 Subject: [PATCH] readme: Update example for Identify() --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 922e019b..4d5b2339 100644 --- a/README.md +++ b/README.md @@ -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 { @@ -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.