FAQ
Hi golang-nuts.

I'd like to be able to handle uncompressing of Bzip2/Gzip/Zip files by
having a function that
checks the archive header, figures out the type of the archive and returns
the correct reader, eg.

package archivereader

func NewReader(f *os.File) (io.Reader, error) {
switch readerType(f) {
case "gzip":
return gzip.NewReader(f)
case "bzip2":
return bzip2.NewReader(f), nil
   case "zip":
// return ???
}
}

This approach works for gzip and bzip2 but archive/zip.NewReader returns
*zip.Reader
which does not implement io.Reader (missing Read method) so I'm struggling
with
creating a correct function signature and figuring out how to use
archive/zip for this.

What's the idiomatic way of doing this in Go ?

Many thanks
Karol

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • David Symonds at Jun 10, 2013 at 1:12 am
    Your approach does not make sense, because gzip/bzip2 are simply
    compressors (and thus operate on a stream that io.Reader/io.Writer can
    model), but zip is an entire archive format that contains multiple
    files.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Karol Hosiawa at Jun 10, 2013 at 5:09 am
    In the case of multiple files in a zip archive I'd like to read them in a
    sequence, the order doesn't matter.

    I found out about io.MultiReader and came up with the following:
    http://play.golang.org/p/StvgCI1urR

    Thanks
    Karol

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 10, '13 at 1:11a
activeJun 10, '13 at 5:09a
posts3
users2
websitegolang.org

2 users in discussion

Karol Hosiawa: 2 posts David Symonds: 1 post

People

Translate

site design / logo © 2022 Grokbase