title: Getting `write too long` error when trying to create tar.gz file from file and directories
body: <p>So I'm trying to crate a tar.gz file file from multiple directories and files. Something with the same usage as:</p>
  
  <pre><code>tar -cvzf sometarfile.tar.gz somedir/ someotherdir/ somefile.json somefile.xml
  </code></pre>
  
  <p>Assuming the directories have other directories inside of them.
  I have this as an input:</p>
  
  <pre><code>    paths := []string{
        "somedir/",
        "someotherdir/",
        "somefile.json",
        "somefile.xml",
      }
  </code></pre>
  
  <p>and using these:</p>
  
  <pre><code>    func TarFilesDirs(paths []string, tarFilePath string ) error {
         // set up the output file
         file, err := os.Create(tarFilePath)
         if err != nil {
             return err
         }
  
         defer file.Close()
         // set up the gzip writer
         gz := gzip.NewWriter(file)
         defer gz.Close()
  
         tw := tar.NewWriter(gz)
         defer tw.Close()
  
         // add each file/dir as needed into the current tar archive
         for _,i := range paths {
            if err := tarit(i, tw); err != nil {
                 return err
            }
         }
  
         return nil
     }
  
  func tarit(source string, tw *tar.Writer) error {
      info, err := os.Stat(source)
      if err != nil {
          return nil
      }
  
      var baseDir string
      if info.IsDir() {
          baseDir = filepath.Base(source)
      }
  
      return filepath.Walk(source,
          func(path string, info os.FileInfo, err error) error {
              if err != nil {
                  return err
              }
  
              header, err := tar.FileInfoHeader(info, info.Name())
              if err != nil {
                  return err
              }
  
              if baseDir != "" {
                  header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source))
              }
  
              if err := tw.WriteHeader(header); err != nil {
                  return err
              }
  
              if info.IsDir() {
                  return nil
              }
  
              file, err := os.Open(path)
              if err != nil {
                  return err
              }
  
              defer file.Close()
  
              _, err = io.Copy(tw, file)
              if err != nil {
                  log.Println("failing here")
                  return err
              }
  
              return err
          })
  }
  </code></pre>
  
  <p><strong>Problem:</strong> if a directory is large I'm getting:</p>
  
  <pre><code>archive/tar: write too long
  </code></pre>
  
  <p>error, when I remove it everything works.</p>
  
  <p>Ran out of ideas and wasted many hours on this trying to find a solution...</p>
  
  <p>Any ideas? </p>
  
  <p>Thanks</p>