Пример #1
0
// readNextChunk creates an io.LimitedReader for the next chunk of data,
// and returns io.EOF if the last chunk has been read.
func readNextChunk(r wire.SyncScanner) (io.Reader, error) {
	id, err := r.ReadOctetString()
	if err != nil {
		return nil, err
	}

	switch id {
	case "DATA":
		return r.ReadBytes()
	case "DONE":
		return nil, io.EOF
	default:
		return nil, fmt.Errorf("expected chunk id 'DATA', but got '%s'", id)
	}
}