MCPcopy
hub / github.com/crowdsecurity/crowdsec / compressFile

Function compressFile

cmd/notification-file/main.go:138–170  ·  view source on GitHub ↗
(src string)

Source from the content-addressed store, hash-verified

136}
137
138func compressFile(src string) error {
139 // Open the source file for reading
140 srcFile, err := os.Open(src)
141 if err != nil {
142 return err
143 }
144 defer srcFile.Close()
145
146 // Create the destination file
147 dstFile, err := os.Create(src + ".gz")
148 if err != nil {
149 return err
150 }
151 defer dstFile.Close()
152
153 // Create a gzip writer
154 gw := gzip.NewWriter(dstFile)
155 defer gw.Close()
156
157 // Read the source file and write its contents to the gzip writer
158 _, err = io.Copy(gw, srcFile)
159 if err != nil {
160 return err
161 }
162
163 // Delete the original (uncompressed) backup file
164 err = os.Remove(src)
165 if err != nil {
166 return err
167 }
168
169 return nil
170}
171
172func WriteToFileWithCtx(ctx context.Context, cfg PluginConfig, log string) error {
173 FileWriteMutex.Lock()

Callers 1

rotateLogFileMethod · 0.85

Calls 3

OpenMethod · 0.80
CloseMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…