MCPcopy
hub / github.com/dgraph-io/dgraph / readGzData

Function readGzData

dgraphtest/load.go:101–128  ·  view source on GitHub ↗
(r io.Reader, encryption bool, encKeyPath string)

Source from the content-addressed store, hash-verified

99}
100
101func readGzData(r io.Reader, encryption bool, encKeyPath string) ([]byte, error) {
102 if encryption {
103 encKey, err := os.ReadFile(encKeyPath)
104 if err != nil {
105 return nil, errors.Wrap(err, "error reading the encryption key from disk")
106 }
107 r, err = enc.GetReader(encKey, r)
108 if err != nil {
109 return nil, errors.Wrap(err, "error creating encrypted reader")
110 }
111 }
112
113 gr, err := gzip.NewReader(r)
114 if err != nil {
115 return nil, errors.Wrapf(err, "error creating gzip reader")
116 }
117 defer func() {
118 if err := gr.Close(); err != nil {
119 log.Printf("[WARNING] error closing gzip reader: %v", err)
120 }
121 }()
122
123 data, err := io.ReadAll(gr)
124 if err != nil {
125 return nil, errors.Wrap(err, "error reading data from io.Reader")
126 }
127 return data, nil
128}
129
130func writeGzData(data []byte, encryption bool, encKeyPath string) (io.Reader, error) {
131 buf := bytes.NewBuffer(nil)

Callers 2

readGzFileFunction · 0.85
modifyACLEntriesFunction · 0.85

Calls 2

GetReaderFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected