title: io.Copy cause cannot allocate memory in golang
body: <p>I use compress/gzip to decompress files</p>
  
  <pre><code>func DecompressZip(src string, target string) error {
      f, err := os.Open(src)
      if err != nil {
          return errors.Wrap(err, "can't open tar source file:"+src)
      }
      defer f.Close()
      zipReader, err := gzip.NewReader(f)
      if err != nil {
          return errors.Wrap(err, "can't gzip source file"+src)
      }
      defer zipReader.Close()
      unzipFile, err := CreateFileAnyway(target) // return *os.file
      if err != nil {
          return errors.Wrap(err, "can't create target file"+target)
      }
      defer unzipFile.Close()
      if _, err := io.Copy(unzipFile, zipReader); err != nil {
          return errors.Wrap(err, "can't unzip to file :"+target)
      }
      return nil
  }
  
  func CreateFileAnyway(path string) (*os.File, error) {
      if _, err := os.Stat(path); err == nil {
          return os.Create(path)
      } else {
          i := len(path)
          for i &gt; 0 &amp;&amp; !os.IsPathSeparator(path[i-1]) {
              i--
          }
          if i &gt; 0 {
              if err := os.MkdirAll(path[:i], 0777); err != nil {
                  return nil, err
              }
          }
          return os.Create(path)
      }
  }
  </code></pre>
  
  <p>this code encounted an error on <code>io.Copy</code>,the log:
  <code>can't unzip to file :***: write ***: cannot allocate memory</code></p>
  
  <p>The ziped file 300M, unziped file is 5G.
  Memory: 2048M.</p>