MCPcopy Create free account
hub / github.com/MG-RAST/Shock / Create

Method Create

shock-server/node/file/index/line.go:33–87  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

31}
32
33func (l *lineRecord) Create(file string) (count int64, format string, err error) {
34 tmpFilePath := fmt.Sprintf("%s/temp/%d%d.idx", conf.PATH_DATA, rand.Int(), rand.Int())
35
36 f, err := os.Create(tmpFilePath)
37 if err != nil {
38 return
39 }
40 defer f.Close()
41
42 format = "array"
43 eof := false
44 curr := int64(0)
45 count = 0
46 buffer_pos := 0 // used to track the location in our byte array
47
48 // Writing index file in 16MB chunks
49 var b [16777216]byte
50 for {
51 // io.EOF error does not get returned from GetReadOffset() until all lines have been read
52 n, er := l.r.GetReadOffset()
53 if er != nil {
54 if er != io.EOF {
55 err = er
56 return
57 }
58 eof = true
59 }
60
61 x := (buffer_pos * 16)
62 if x == 16777216 {
63 f.Write(b[:])
64 buffer_pos = 0
65 x = 0
66 }
67 y := x + 8
68 z := x + 16
69
70 binary.LittleEndian.PutUint64(b[x:y], uint64(curr))
71 binary.LittleEndian.PutUint64(b[y:z], uint64(n))
72 curr += int64(n)
73 count += 1
74 buffer_pos += 1
75
76 if eof {
77 break
78 }
79 }
80 if buffer_pos != 0 {
81 f.Write(b[:buffer_pos*16])
82 }
83
84 err = os.Rename(tmpFilePath, file)
85
86 return
87}
88
89func (l *lineRecord) Close() (err error) {
90 l.f.Close()

Callers

nothing calls this directly

Calls 4

CreateMethod · 0.65
CloseMethod · 0.65
GetReadOffsetMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected