예제 #1
0
파일: zip.go 프로젝트: ndlib/bendo
// OpenZipWriter creates a new bundle in the given store using the given id and
// bundle number. It returns a zip writer which is then saved into the store.
func OpenZipWriter(s store.Store, id string, n int) (*Zipwriter, error) {
	f, err := s.Create(sugar(id, n))
	if err != nil {
		return nil, err
	}
	return &Zipwriter{
		f:      f,
		Writer: bagit.NewWriter(f, strings.TrimSuffix(id, ".zip")),
	}, nil
}
예제 #2
0
파일: zip.go 프로젝트: ndlib/bendo
// OpenBundle opens the provided key in the given store, and wraps it in a
// bagit reader.
func OpenBundle(s store.Store, key string) (*BagreaderCloser, error) {
	stream, size, err := s.Open(key)
	if err != nil {
		return nil, err
	}
	var result *BagreaderCloser
	r, err := bagit.NewReader(stream, size)
	if err == nil {
		result = &BagreaderCloser{
			Reader: r,
			f:      stream,
		}
	} else {
		stream.Close()
	}
	return result, err
}