README.md 754 字节
Newer Older
1 2 3 4 5 6 7 8 9 10
# RecordIO

## Write

```go
f, e := os.Create("a_file.recordio")
w := recordio.NewWriter(f)
w.Write([]byte("Hello"))
w.Write([]byte("World!"))
w.Close()
11
f.Close()
12 13 14 15 16 17 18 19 20 21
```

## Read

1. Load chunk index:

   ```go
   f, e := os.Open("a_file.recordio")
   idx, e := recordio.LoadIndex(f)
   fmt.Println("Total records: ", idx.Len())
22
   f.Close()
23 24 25 26 27 28 29 30 31 32 33 34
   ```

2. Create one or more scanner to read a range of records.  The
   following example reads the range
   [1, 3), i.e., the second and the third records:

   ```go
   f, e := os.Open("a_file.recordio")
   s := recrodio.NewScanner(f, idx, 1, 3)
   for s.Scan() {
      fmt.Println(string(s.Record()))
   }
H
Helin Wang 已提交
35
   if s.Err() != nil {
36 37
      log.Fatalf("Something wrong with scanning: %v", e)
   }
38
   f.Close()
39
   ```