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

Method Create

shock-server/node/file/index/record.go:34–90  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

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

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