(src string)
| 136 | } |
| 137 | |
| 138 | func 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 | |
| 172 | func WriteToFileWithCtx(ctx context.Context, cfg PluginConfig, log string) error { |
| 173 | FileWriteMutex.Lock() |
no test coverage detected
searching dependent graphs…