Skip to content

Commit

Permalink
internal/code: copy directly from source to destination
Browse files Browse the repository at this point in the history
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 0da5286
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/code/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0da5286

Please sign in to comment.