Пример #1
0
// AsSource returns an interface for reading the resource.
func (res *memoryResource) AsSource() (buf serial.SeekingReadCloser, err error) {
	if res.writeLocks == 0 {
		res.readLocks++
		buf = serial.NewByteStoreFromData(res.data, func([]byte) { res.readLocks-- })
	} else {
		err = fmt.Errorf("Cannot open for reading")
	}

	return
}
Пример #2
0
// AsSink returns an interface for writing the resource.
func (res *memoryResource) AsSink() (buf serial.SeekingWriteCloser, err error) {
	if res.readLocks == 0 && res.writeLocks == 0 {
		res.writeLocks++
		buf = serial.NewByteStoreFromData(nil, func(data []byte) {
			res.data = data
			res.writeLocks--
		})
	} else {
		err = fmt.Errorf("Cannot open for writing")
	}

	return
}
func (library *ReleaseStoreLibrary) saveAndReloadObjpropData(data []byte, path string, name string) (provider objprop.Provider, reader serial.SeekingReadCloser) {
	newResource, err := library.saveResource(data, path, name)

	if err == nil {
		reader, err = newResource.AsSource()
	}
	if err == nil {
		provider, err = dosObjprop.NewProvider(reader, library.descriptors)
		if err != nil {
			reader.Close()
		}
	}
	if err != nil {
		log.Printf("Failed to store in sink, buffering: %v\n", err)
		reader = serial.NewByteStoreFromData(data, func([]byte) {})
		provider, _ = dosObjprop.NewProvider(reader, library.descriptors)
	}

	return
}