Skip to content
Permalink
Browse files

internal/code: copy directly from source to destination

Instead of reading entire source into a buffer first, we can directly
copy its contents to the writer. That is potentially more efficient.
  • Loading branch information...
dmitshur committed May 8, 2019
1 parent fb40c19 commit 0da52861b4a5fd190f4fd1d852da39aba08ed559
Showing with 4 additions and 4 deletions.
  1. +4 −4 internal/code/module.go
@@ -23,7 +23,6 @@ import (
"github.com/shurcooL/go/vfs/godocfs/vfsutil"
"github.com/shurcooL/home/internal/mod"
"github.com/shurcooL/httperror"
"golang.org/x/tools/godoc/vfs"
"sourcegraph.com/sourcegraph/go-vcs/vcs"
"sourcegraph.com/sourcegraph/go-vcs/vcs/git"
)
@@ -193,15 +192,16 @@ func (h ModuleHandler) serveZip(w http.ResponseWriter, repo *git.Repository, com
// We only care about files.
return nil
}
b, err := vfs.ReadFile(fs, name)
dst, err := z.Create(modulePath + "@" + version + name)
if err != nil {
return err
}
f, err := z.Create(modulePath + "@" + version + name)
src, err := fs.Open(name)
if err != nil {
return err
}
_, err = f.Write(b)
_, err = io.Copy(dst, src)
src.Close()
return err
})
if err != nil {

0 comments on commit 0da5286

Please sign in to comment.
You can’t perform that action at this time.