aboutsummaryrefslogtreecommitdiff
path: root/go/gcexportdata/gcexportdata.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/gcexportdata/gcexportdata.go')
-rw-r--r--go/gcexportdata/gcexportdata.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/go/gcexportdata/gcexportdata.go b/go/gcexportdata/gcexportdata.go
index fc8beea5d..cec819d64 100644
--- a/go/gcexportdata/gcexportdata.go
+++ b/go/gcexportdata/gcexportdata.go
@@ -50,11 +50,24 @@ func Find(importPath, srcDir string) (filename, path string) {
// additional trailing data beyond the end of the export data.
func NewReader(r io.Reader) (io.Reader, error) {
buf := bufio.NewReader(r)
- _, err := gcimporter.FindExportData(buf)
- // If we ever switch to a zip-like archive format with the ToC
- // at the end, we can return the correct portion of export data,
- // but for now we must return the entire rest of the file.
- return buf, err
+ _, size, err := gcimporter.FindExportData(buf)
+ if err != nil {
+ return nil, err
+ }
+
+ if size >= 0 {
+ // We were given an archive and found the __.PKGDEF in it.
+ // This tells us the size of the export data, and we don't
+ // need to return the entire file.
+ return &io.LimitedReader{
+ R: buf,
+ N: size,
+ }, nil
+ } else {
+ // We were given an object file. As such, we don't know how large
+ // the export data is and must return the entire file.
+ return buf, nil
+ }
}
// Read reads export data from in, decodes it, and returns type