MCPcopy
hub / github.com/hasura/graphql-engine / Buffer

Method Buffer

cli/migrate/migration.go:115–151  ·  view source on GitHub ↗

Buffer buffers Body up to BufferSize. Calling this function blocks. Call with goroutine.

()

Source from the content-addressed store, hash-verified

113// Buffer buffers Body up to BufferSize.
114// Calling this function blocks. Call with goroutine.
115func (m *Migration) Buffer() error {
116 var op errors.Op = "migrate.Migration.Buffer"
117 if m.Body == nil {
118 return nil
119 }
120
121 m.StartedBuffering = time.Now()
122
123 b := bufio.NewReaderSize(m.Body, int(m.BufferSize))
124
125 // start reading from body, peek won't move the read pointer though
126 // poor man's solution?
127 if _, err := b.Peek(int(m.BufferSize)); err != nil && err != io.EOF {
128 return errors.E(op, err)
129 }
130
131 m.FinishedBuffering = time.Now()
132
133 // write to bufferWriter, this will block until
134 // something starts reading from m.Buffer
135 n, err := b.WriteTo(m.bufferWriter)
136 if err != nil {
137 return errors.E(op, err)
138 }
139
140 m.FinishedReading = time.Now()
141 m.BytesRead = n
142
143 // close bufferWriter so Buffer knows that there is no
144 // more data coming
145 m.bufferWriter.Close()
146
147 // it's safe to close the Body too
148 m.Body.Close()
149
150 return nil
151}

Callers 7

squashUpMethod · 0.80
squashDownMethod · 0.80
readMethod · 0.80
readUpMethod · 0.80
readDownMethod · 0.80
readUpFromVersionMethod · 0.80
readDownFromVersionMethod · 0.80

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected