Example #1
0
func Get(rf codec.Reader, id codec.ID) (codec.Song, error) {
	top, child := id.Pop()
	r, _, err := rf()
	if err != nil {
		return nil, err
	}
	defer r.Close()
	var song codec.Song
	f := func(d *rardecode.Reader, fh *rardecode.FileHeader) (stop bool) {
		if fh.Name != top {
			return false
		}
		var b []byte
		// TODO: Wait until needed to read the data. However, this should cache the data
		// and then close the reader.
		b, err = ioutil.ReadAll(d)
		if err != nil {
			return true
		}
		song, err = codec.ByExtensionID(top, child, func() (io.ReadCloser, int64, error) {
			return ioutil.NopCloser(bytes.NewReader([]byte(b))), int64(len(b)), nil
		})
		return true
	}
	err = read(r, f)
	if err == nil && song == nil {
		err = fmt.Errorf("rar: %v unfound", top)
	}
	return song, err
}
Example #2
0
func (d *Drive) GetSong(id codec.ID) (codec.Song, error) {
	path, child := id.Pop()
	f := d.Files[path]
	if f == nil {
		return nil, fmt.Errorf("missing %v", path)
	}
	return codec.ByExtensionID(f.FileExtension, child, d.reader(path))
}
Example #3
0
func (f *File) GetSong(id codec.ID) (codec.Song, error) {
	top, child := id.Pop()
	return codec.ByExtensionID(top, child, fileReader(top))
}