func parsePackageDefinition(reader *tar.Reader, pkg *Package, details *Details) error {
	cin := make(chan int)
	cout := make(chan *Token)
	cerr := make(chan error)
	cdone := make(chan bool)
	go parseSimpleSexp(cin, cout, cdone)
	go readPackageDefinition(cout, cerr, pkg, details)
	bytes := make([]byte, 256)
	for {
		n, err := reader.Read(bytes)
		if err == io.EOF {
			cdone <- true
			break
		}
		if err != nil {
			cdone <- true
			return err
		}
		for _, b := range bytes[:n] {
			select {
			case err = <-cerr:
				return err
			default:
				cin <- int(b)
			}
		}
	}
	return <-cerr
}
Esempio n. 2
0
func getTarContent(tr *tar.Reader, name string) []byte {
	for {
		hdr, err := tr.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			panic(err)
		}

		if hdr.Name == name {
			ret := make([]byte, hdr.Size)
			n, err := tr.Read(ret)
			if int64(n) != hdr.Size {
				panic("Size mismatch")
			}
			if err != nil {
				panic(err)
			}
			return ret
		}
	}
	panic("File not found!")
}