LEFT | RIGHT |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package goobj implements reading of Go object files and archives. | 5 // Package goobj implements reading of Go object files and archives. |
6 // | 6 // |
7 // TODO(rsc): Decide where this package should live. (golang.org/issue/6932) | 7 // TODO(rsc): Decide where this package should live. (golang.org/issue/6932) |
8 // TODO(rsc): Decide the appropriate integer types for various fields. | 8 // TODO(rsc): Decide the appropriate integer types for various fields. |
9 // TODO(rsc): Write tests. (File format still up in the air a little.) | 9 // TODO(rsc): Write tests. (File format still up in the air a little.) |
10 package goobj | 10 package goobj |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // 40:48 mode | 503 // 40:48 mode |
504 // 48:58 size | 504 // 48:58 size |
505 // 58:60 magic - `\n | 505 // 58:60 magic - `\n |
506 // We only care about name, size, and magic. | 506 // We only care about name, size, and magic. |
507 // The fields are space-padded on the right. | 507 // The fields are space-padded on the right. |
508 // The size is in decimal. | 508 // The size is in decimal. |
509 // The file data - size bytes - follows the header. | 509 // The file data - size bytes - follows the header. |
510 // Headers are 2-byte aligned, so if size is odd, an extra paddi
ng | 510 // Headers are 2-byte aligned, so if size is odd, an extra paddi
ng |
511 // byte sits between the file data and the next header. | 511 // byte sits between the file data and the next header. |
512 // The file data that follows is padded to an even number of byt
es: | 512 // The file data that follows is padded to an even number of byt
es: |
513 » » // if size is odd, an extra padding byte is inserted after the d
ata. | 513 » » // if size is odd, an extra padding byte is inserted betw the ne
xt header. |
514 if len(data) < 60 { | 514 if len(data) < 60 { |
515 return errTruncatedArchive | 515 return errTruncatedArchive |
516 } | 516 } |
517 if !bytes.Equal(data[58:60], archiveMagic) { | 517 if !bytes.Equal(data[58:60], archiveMagic) { |
518 return errCorruptArchive | 518 return errCorruptArchive |
519 } | 519 } |
520 name := trimSpace(data[0:16]) | 520 name := trimSpace(data[0:16]) |
521 size, err := strconv.ParseInt(trimSpace(data[48:58]), 10, 64) | 521 size, err := strconv.ParseInt(trimSpace(data[48:58]), 10, 64) |
522 if err != nil { | 522 if err != nil { |
523 return errCorruptArchive | 523 return errCorruptArchive |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 r.readFull(r.tmp[:7]) | 658 r.readFull(r.tmp[:7]) |
659 if !bytes.Equal(r.tmp[:7], []byte("\xffgo13ld")) { | 659 if !bytes.Equal(r.tmp[:7], []byte("\xffgo13ld")) { |
660 return r.error(errCorruptObject) | 660 return r.error(errCorruptObject) |
661 } | 661 } |
662 | 662 |
663 return nil | 663 return nil |
664 } | 664 } |
LEFT | RIGHT |