1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
6 Package zip provides support for reading and writing ZIP archives.
8 See: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
10 This package does not support ZIP64 or disk spanning.
17 // Compression methods.
24 fileHeaderSignature = 0x04034b50
25 directoryHeaderSignature = 0x02014b50
26 directoryEndSignature = 0x06054b50
27 fileHeaderLen = 30 // + filename + extra
28 directoryHeaderLen = 46 // + filename + extra + comment
29 directoryEndLen = 22 // + comment
30 dataDescriptorLen = 12
33 type FileHeader struct {
39 ModifiedTime uint16 // MS-DOS time
40 ModifiedDate uint16 // MS-DOS date
43 UncompressedSize uint32
48 type directoryEnd struct {
49 diskNbr uint16 // unused
50 dirDiskNbr uint16 // unused
51 dirRecordsThisDisk uint16 // unused
52 directoryRecords uint16
54 directoryOffset uint32 // relative to file
59 func recoverError(err *os.Error) {
60 if e := recover(); e != nil {
61 if osErr, ok := e.(os.Error); ok {
69 // msDosTimeToTime converts an MS-DOS date and time into a time.Time.
70 // The resolution is 2s.
71 // See: http://msdn.microsoft.com/en-us/library/ms724247(v=VS.85).aspx
72 func msDosTimeToTime(dosDate, dosTime uint16) time.Time {
74 // date bits 0-4: day of month; 5-8: month; 9-15: years since 1980
75 Year: int64(dosDate>>9 + 1980),
76 Month: int(dosDate >> 5 & 0xf),
77 Day: int(dosDate & 0x1f),
79 // time bits 0-4: second/2; 5-10: minute; 11-15: hour
80 Hour: int(dosTime >> 11),
81 Minute: int(dosTime >> 5 & 0x3f),
82 Second: int(dosTime & 0x1f * 2),
86 // Mtime_ns returns the modified time in ns since epoch.
87 // The resolution is 2s.
88 func (h *FileHeader) Mtime_ns() int64 {
89 t := msDosTimeToTime(h.ModifiedDate, h.ModifiedTime)
90 return t.Seconds() * 1e9