title: How can I stream data from a file within a gzip archive so that I can test the header?
body: <p>I am trying to write an extraction tool, in Go, which will decompress/extract several types of archive files. To check the type of file, I am making use of the magic numbers, and have been successful in checking for <code>.gz</code> and <code>.tar</code> archives directly, but for any <code>.tar.gz</code>/<code>.tgz</code> archives, I do not seem to be able to check the tar file within the Gzip bundle.</p>
  <p>My current train of thought is that I need to take the output of <code>gzip.NewReader(f)</code> and feed pull the header of its output, but this is not working.</p>
  <pre><code>f, err := os.Open(file)
  if err != null {
    return fmt.Errorf(&quot;problem opening %s&quot;, filename)
  }
  r, _ := gzip.NewReader(f)
  h, err := GetHeader(r, l)
  </code></pre>
  <p>Here, <code>GetHeader</code> is...</p>
  <pre><code>func GetHeader(r io.Reader, l uint32) (in []byte, err error) {
      fmt.Println(&quot;Here C&quot;)
      in = make([]byte, l)
      n := 0
      n, err = io.ReadFull(r, in)
      if err != nil &amp;&amp; err != io.EOF &amp;&amp; err != io.ErrUnexpectedEOF {
          fmt.Println(&quot;Here D&quot;)
          return nil, err
      }
      fmt.Println(n)
      in = in[:n]
      return in, nil
  }
  </code></pre>
  <p>It is used for both checking the Gzip and Tar archive on their own successfully, and in all, <code>l</code> is set to <code>uint32 3072</code>.</p>
  <p>I can only assume that I'm missing something pretty trivial here, but at the minute I'm at a loss.</p>
  <p>If there is anyone that can assist me with this, it would be greatly appreciated.</p>