Пример #1
0
// Read reads data from a BLOB incrementally.
// (See http://sqlite.org/c3ref/blob_read.html)
func (r *BlobReader) Read(v []byte) (int, error) {
	if len(v) == 0 {
		return 0, nil
	}
	size, err := r.Size()
	if err != nil {
		return 0, err
	}
	if r.ReadOffset >= size {
		return 0, io.EOF
	}
	if len(v) > (size - r.ReadOffset) {
		v = v[0 : size-r.ReadOffset]
	}
	p := &v[0]
	n := len(v)
	rv := C.sqlite3_blob_read(r.bl, unsafe.Pointer(p), C.int(n), C.int(r.ReadOffset))
	if rv != C.SQLITE_OK {
		return 0, r.c.error(rv, "BlobReader.Read")
	}
	r.ReadOffset += n
	return n, nil
}
Пример #2
0
// Read reads data from a BLOB incrementally.
// (See http://sqlite.org/c3ref/blob_read.html)
func (r *BlobReader) Read(v []byte) (int, error) {
	if len(v) == 0 {
		return 0, nil
	}
	size, err := r.Size()
	if err != nil {
		return 0, err
	}
	if r.offset >= size {
		return 0, io.EOF
	}
	n := size - r.offset
	if len(v) < int(n) {
		n = int32(len(v))
	}
	p := &v[0]
	rv := C.sqlite3_blob_read(r.bl, unsafe.Pointer(p), C.int(n), C.int(r.offset))
	if rv != C.SQLITE_OK {
		return 0, r.c.error(rv, "BlobReader.Read")
	}
	r.offset += n
	return int(n), nil
}