Esempio n. 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)
	}
}
Esempio n. 2
0
func readNextDirListEntry(s wire.SyncScanner) (entry *DirEntry, done bool, err error) {
	id, err := s.ReadOctetString()
	if err != nil {
		return
	}

	if id == "DONE" {
		done = true
		return
	} else if id != "DENT" {
		err = fmt.Errorf("error reading dir entries: expected dir entry ID 'DENT', but got '%s'", id)
		return
	}

	mode, err := s.ReadFileMode()
	if err != nil {
		err = fmt.Errorf("error reading dir entries: error reading file mode: %v", err)
		return
	}
	size, err := s.ReadInt32()
	if err != nil {
		err = fmt.Errorf("error reading dir entries: error reading file size: %v", err)
		return
	}
	mtime, err := s.ReadTime()
	if err != nil {
		err = fmt.Errorf("error reading dir entries: error reading file time: %v", err)
		return
	}
	name, err := s.ReadString()
	if err != nil {
		err = fmt.Errorf("error reading dir entries: error reading file name: %v", err)
		return
	}

	done = false
	entry = &DirEntry{
		Name:       name,
		Mode:       mode,
		Size:       size,
		ModifiedAt: mtime,
	}
	return
}