@@ -21,7 +21,8 @@ func compressAndUpload(cfg *Config, pcapPath string) error {
2121
2222 log .Printf ("Processing %s" , pcapPath )
2323
24- if _ , err := os .Stat (pcapPath ); err != nil {
24+ originalInfo , err := os .Stat (pcapPath )
25+ if err != nil {
2526 return fmt .Errorf ("pcap file not found: %w" , err )
2627 }
2728
@@ -32,6 +33,17 @@ func compressAndUpload(cfg *Config, pcapPath string) error {
3233 return fmt .Errorf ("bzip2 failed: %s: %w" , string (out ), err )
3334 }
3435 compressedPath := pcapPath + ".bz2"
36+ compressedInfo , err := os .Stat (compressedPath )
37+ if err != nil {
38+ return fmt .Errorf ("stat compressed file: %w" , err )
39+ }
40+ compressionStats := formatCompressionStats (
41+ filepath .Base (pcapPath ),
42+ filepath .Base (compressedPath ),
43+ originalInfo .Size (),
44+ compressedInfo .Size (),
45+ )
46+ log .Printf ("Compression complete: %s" , compressionStats )
3547
3648 // Upload to S3 with year/month/day folder structure
3749 now := time .Now ().UTC ()
@@ -54,6 +66,20 @@ func compressAndUpload(cfg *Config, pcapPath string) error {
5466 return nil
5567}
5668
69+ func formatCompressionStats (originalName , compressedName string , originalSize , compressedSize int64 ) string {
70+ ratioText := "ratio unavailable"
71+
72+ if originalSize == 0 {
73+ ratioText = "ratio unavailable: empty input file"
74+ } else if compressedSize == 0 {
75+ ratioText = "ratio unavailable: empty compressed file"
76+ } else {
77+ ratioText = fmt .Sprintf ("ratio %.2f:1" , float64 (originalSize )/ float64 (compressedSize ))
78+ }
79+
80+ return fmt .Sprintf ("%s -> %s (%d bytes -> %d bytes, %s)" , originalName , compressedName , originalSize , compressedSize , ratioText )
81+ }
82+
5783func uploadToS3 (cfg * Config , filePath , key string ) error {
5884 ctx := context .Background ()
5985
0 commit comments