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.
8 error_ "crypto/openpgp/error"
12 // Reader reads packets from an io.Reader and allows packets to be 'unread' so
13 // that they result from the next call to Next.
19 // Next returns the most recently unread Packet, or reads another packet from
20 // the top-most io.Reader. Unknown packet types are skipped.
21 func (r *Reader) Next() (p Packet, err error) {
24 r.q = r.q[:len(r.q)-1]
28 for len(r.readers) > 0 {
29 p, err = Read(r.readers[len(r.readers)-1])
34 r.readers = r.readers[:len(r.readers)-1]
37 if _, ok := err.(error_.UnknownPacketTypeError); !ok {
45 // Push causes the Reader to start reading from a new io.Reader. When an EOF
46 // error is seen from the new io.Reader, it is popped and the Reader continues
47 // to read from the next most recent io.Reader.
48 func (r *Reader) Push(reader io.Reader) {
49 r.readers = append(r.readers, reader)
52 // Unread causes the given Packet to be returned from the next call to Next.
53 func (r *Reader) Unread(p Packet) {
57 func NewReader(r io.Reader) *Reader {
60 readers: []io.Reader{r},