github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/third_party/code.google.com/p/go.crypto/openpgp/packet/compressed.go (about) 1 // Copyright 2011 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. 4 5 package packet 6 7 import ( 8 "camlistore.org/third_party/code.google.com/p/go.crypto/openpgp/errors" 9 "compress/flate" 10 "compress/zlib" 11 "io" 12 "strconv" 13 ) 14 15 // Compressed represents a compressed OpenPGP packet. The decompressed contents 16 // will contain more OpenPGP packets. See RFC 4880, section 5.6. 17 type Compressed struct { 18 Body io.Reader 19 } 20 21 func (c *Compressed) parse(r io.Reader) error { 22 var buf [1]byte 23 _, err := readFull(r, buf[:]) 24 if err != nil { 25 return err 26 } 27 28 switch buf[0] { 29 case 1: 30 c.Body = flate.NewReader(r) 31 case 2: 32 c.Body, err = zlib.NewReader(r) 33 default: 34 err = errors.UnsupportedError("unknown compression algorithm: " + strconv.Itoa(int(buf[0]))) 35 } 36 37 return err 38 }