// positionBytes is the size of an encoded position.
const positionBytes = 16
+// Records is a file of fixed-size Records, numbered from 0. Record n starts at
+// byte n*size. A record that was never written reads as zeros. An index is data
+// that the day files can give again, so Records cuts a partial record at the
+// end of the file.
+type Records struct {
+ file *os.File
+ size int
+ count int
+}
+
// openRecords opens or creates the record file at path with records of size
// bytes.
func openRecords(path string, size int) (*Records, error) {
return r, nil
}
-// encodePosition writes place into the first positionBytes bytes of record.
-func encodePosition(record []byte, place Position) {
- binary.LittleEndian.PutUint32(record[0:], place.day)
- binary.LittleEndian.PutUint32(record[4:], place.length)
- binary.LittleEndian.PutUint64(record[8:], place.offset)
-}
-
-// decodePosition reads a position from the first positionBytes bytes of record.
-func decodePosition(record []byte) Position {
- return Position{
- day: binary.LittleEndian.Uint32(record[0:]),
- length: binary.LittleEndian.Uint32(record[4:]),
- offset: binary.LittleEndian.Uint64(record[8:]),
- }
-}
-
-// Records is a file of fixed-size Records, numbered from 0. Record n starts at
-// byte n*size. A record that was never written reads as zeros. An index is data
-// that the day files can give again, so Records cuts a partial record at the
-// end of the file.
-type Records struct {
- file *os.File
- size int
- count int
-}
-
// Read returns record n, or false when the file does not reach it.
func (r *Records) Read(n int) ([]byte, bool, error) {
if n >= r.count {
func (r *Records) Close() error {
return r.file.Close()
}
+
+// encodePosition writes place into the first positionBytes bytes of record.
+func encodePosition(record []byte, place Position) {
+ binary.LittleEndian.PutUint32(record[0:], place.day)
+ binary.LittleEndian.PutUint32(record[4:], place.length)
+ binary.LittleEndian.PutUint64(record[8:], place.offset)
+}
+
+// decodePosition reads a position from the first positionBytes bytes of record.
+func decodePosition(record []byte) Position {
+ return Position{
+ day: binary.LittleEndian.Uint32(record[0:]),
+ length: binary.LittleEndian.Uint32(record[4:]),
+ offset: binary.LittleEndian.Uint64(record[8:]),
+ }
+}