Пример #1
0
Файл: rar.go Проект: shazow/mog
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
}
Пример #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))
}
Пример #3
0
Файл: file.go Проект: shazow/mog
func (f *File) GetSong(id codec.ID) (codec.Song, error) {
	top, child := id.Pop()
	return codec.ByExtensionID(top, child, fileReader(top))
}