Last active
March 17, 2022 20:28
-
-
Save robherley/c1e474e07aa6dc01b01610ee29a379db to your computer and use it in GitHub Desktop.
Checking Chunk Uploads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/md5" | |
"fmt" | |
"os" | |
) | |
const chunkSize = 8388608 | |
func md5String(data []byte) string { | |
return fmt.Sprintf("%x", md5.Sum(data)) | |
} | |
func main() { | |
corrupted, err := os.ReadFile("corrupted-339147984") | |
if err != nil { | |
panic(err) | |
} | |
original, err := os.ReadFile("data-339147984") | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("corrupted sum:", md5String(corrupted)) | |
fmt.Println("original sum:", md5String(original)) | |
fmt.Println("--------") | |
start := 0 | |
end := chunkSize | |
for end <= len(original) { | |
originalChunk := original[start:end] | |
corruptChunk := corrupted[start:end] | |
fmt.Printf("chunk %d (%d -> %d): ", start/chunkSize, start, end-1) | |
if md5String(originalChunk) == md5String(corruptChunk) { | |
fmt.Println("match π’") | |
} else { | |
fmt.Println("mismatch π΄") | |
} | |
if end == len(original) { | |
break | |
} | |
start += chunkSize | |
end += chunkSize | |
if end > len(original) { | |
end = len(original) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
corrupted sum: 3cf813bae0337f17ca004a29fd6051fe | |
original sum: 9e5edb81ad0891d1269dbe951123d0ab | |
-------- | |
chunk 0 (0 -> 8388607): match π’ | |
chunk 1 (8388608 -> 16777215): match π’ | |
chunk 2 (16777216 -> 25165823): match π’ | |
chunk 3 (25165824 -> 33554431): match π’ | |
chunk 4 (33554432 -> 41943039): match π’ | |
chunk 5 (41943040 -> 50331647): match π’ | |
chunk 6 (50331648 -> 58720255): match π’ | |
chunk 7 (58720256 -> 67108863): match π’ | |
chunk 8 (67108864 -> 75497471): match π’ | |
chunk 9 (75497472 -> 83886079): match π’ | |
chunk 10 (83886080 -> 92274687): match π’ | |
chunk 11 (92274688 -> 100663295): match π’ | |
chunk 12 (100663296 -> 109051903): match π’ | |
chunk 13 (109051904 -> 117440511): match π’ | |
chunk 14 (117440512 -> 125829119): match π’ | |
chunk 15 (125829120 -> 134217727): match π’ | |
chunk 16 (134217728 -> 142606335): match π’ | |
chunk 17 (142606336 -> 150994943): match π’ | |
chunk 18 (150994944 -> 159383551): match π’ | |
chunk 19 (159383552 -> 167772159): match π’ | |
chunk 20 (167772160 -> 176160767): match π’ | |
chunk 21 (176160768 -> 184549375): match π’ | |
chunk 22 (184549376 -> 192937983): match π’ | |
chunk 23 (192937984 -> 201326591): match π’ | |
chunk 24 (201326592 -> 209715199): match π’ | |
chunk 25 (209715200 -> 218103807): match π’ | |
chunk 26 (218103808 -> 226492415): match π’ | |
chunk 27 (226492416 -> 234881023): match π’ | |
chunk 28 (234881024 -> 243269631): match π’ | |
chunk 29 (243269632 -> 251658239): match π’ | |
chunk 30 (251658240 -> 260046847): match π’ | |
chunk 31 (260046848 -> 268435455): match π’ | |
chunk 32 (268435456 -> 276824063): mismatch π΄ | |
chunk 33 (276824064 -> 285212671): match π’ | |
chunk 34 (285212672 -> 293601279): match π’ | |
chunk 35 (293601280 -> 301989887): match π’ | |
chunk 36 (301989888 -> 310378495): match π’ | |
chunk 37 (310378496 -> 318767103): match π’ | |
chunk 38 (318767104 -> 327155711): match π’ | |
chunk 39 (327155712 -> 335544319): match π’ | |
chunk 40 (335544320 -> 339147983): match π’ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment