MCPcopy Index your code
hub / github.com/FiloSottile/age / Write

Method Write

internal/stream/stream.go:195–219  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

193}
194
195func (w *EncryptWriter) Write(p []byte) (n int, err error) {
196 if w.err != nil {
197 return 0, w.err
198 }
199 if len(p) == 0 {
200 return 0, nil
201 }
202
203 total := len(p)
204 for len(p) > 0 {
205 n := min(len(p), ChunkSize-w.buf.Len())
206 w.buf.Write(p[:n])
207 p = p[n:]
208
209 // Only flush if there's a full chunk with bytes still to write, or we
210 // can't know if this is the last chunk yet.
211 if w.buf.Len() == ChunkSize && len(p) > 0 {
212 if err := w.flushChunk(notLastChunk); err != nil {
213 w.err = err
214 return 0, err
215 }
216 }
217 }
218 return total, nil
219}
220
221// Close flushes the last chunk. It does not close the underlying Writer.
222func (w *EncryptWriter) Close() error {

Callers 13

testVectorRoundTripFunction · 0.95
testRoundTripFunction · 0.95
TestDecryptReaderAtFunction · 0.95
flushChunkMethod · 0.45

Calls 1

flushChunkMethod · 0.95