Example #1
0
// Opens a space for reading given a reader, and an offset/length of
// the spaces position within the file.
func openSpace(reader io.ReadSeeker, id []byte, offset, length int64) *Space {
	if st, err := findSpaceIndex(reader, offset, length); err == nil {

		return &Space{
			Id:     id,
			index:  st,
			reader: reader,
			blocks: blocks.NewReader(reader, 4096),
			offset: offset,
			length: length,
		}
	}

	return nil
}
Example #2
0
// Finds and returns an index by it's name and value.
func (s *Space) findIndex(name, value string) *blocks.Reader {
	if val, err := s.index.Get([]byte("i" + name + ":" + value)); err == nil {
		// The entry in the SSTable index for indexes
		// is variable length integers integers for the
		// offset and length of the index within
		// the file. In this case, we just need the
		// offset to find it's starting point.
		offset := binary.ReadUvarint(bytes.NewReader(val))

		// An index is block encoded, so fire up
		// a block reader, and seek to the start
		// of the index.
		reader := blocks.NewReader(s.reader, 4096)
		reader.Seek(s.offset+offset, 0)

		return reader
	}

	return nil
}