OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 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 bzip2 implements bzip2 decompression. | 5 // Package bzip2 implements bzip2 decompression. |
6 package bzip2 | 6 package bzip2 |
7 | 7 |
8 import "io" | 8 import "io" |
9 | 9 |
10 // There's no RFC for bzip2. I used the Wikipedia page for reference and a lot | 10 // There's no RFC for bzip2. I used the Wikipedia page for reference and a lot |
(...skipping 24 matching lines...) Expand all Loading... |
35 tPos uint32 // Index of the next output byte in tt. | 35 tPos uint32 // Index of the next output byte in tt. |
36 | 36 |
37 preRLE []uint32 // contains the RLE data still to be processed. | 37 preRLE []uint32 // contains the RLE data still to be processed. |
38 preRLEUsed int // number of entries of preRLE used. | 38 preRLEUsed int // number of entries of preRLE used. |
39 lastByte int // the last byte value seen. | 39 lastByte int // the last byte value seen. |
40 byteRepeats uint // the number of repeats of lastByte seen. | 40 byteRepeats uint // the number of repeats of lastByte seen. |
41 repeats uint // the number of copies of lastByte to output. | 41 repeats uint // the number of copies of lastByte to output. |
42 } | 42 } |
43 | 43 |
44 // NewReader returns an io.Reader which decompresses bzip2 data from r. | 44 // NewReader returns an io.Reader which decompresses bzip2 data from r. |
| 45 // If r does not also implement io.ByteReader, |
| 46 // the decompressor may read more data than necessary from r. |
45 func NewReader(r io.Reader) io.Reader { | 47 func NewReader(r io.Reader) io.Reader { |
46 bz2 := new(reader) | 48 bz2 := new(reader) |
47 bz2.br = newBitReader(r) | 49 bz2.br = newBitReader(r) |
48 return bz2 | 50 return bz2 |
49 } | 51 } |
50 | 52 |
51 const bzip2FileMagic = 0x425a // "BZ" | 53 const bzip2FileMagic = 0x425a // "BZ" |
52 const bzip2BlockMagic = 0x314159265359 | 54 const bzip2BlockMagic = 0x314159265359 |
53 const bzip2FinalMagic = 0x177245385090 | 55 const bzip2FinalMagic = 0x177245385090 |
54 | 56 |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 494 |
493 // updateCRC updates the crc value to incorporate the data in b. | 495 // updateCRC updates the crc value to incorporate the data in b. |
494 // The initial value is 0. | 496 // The initial value is 0. |
495 func updateCRC(val uint32, b []byte) uint32 { | 497 func updateCRC(val uint32, b []byte) uint32 { |
496 crc := ^val | 498 crc := ^val |
497 for _, v := range b { | 499 for _, v := range b { |
498 crc = crctab[byte(crc>>24)^v] ^ (crc << 8) | 500 crc = crctab[byte(crc>>24)^v] ^ (crc << 8) |
499 } | 501 } |
500 return ^crc | 502 return ^crc |
501 } | 503 } |
OLD | NEW |