Skip to content

Instantly share code, notes, and snippets.

@c-nv-s
Forked from DenoGeek/combine.go
Created November 26, 2023 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c-nv-s/11365d54fa58bcfca1968f16aab8b29a to your computer and use it in GitHub Desktop.
Save c-nv-s/11365d54fa58bcfca1968f16aab8b29a to your computer and use it in GitHub Desktop.
Recombine file chunks
chunkSizeInBytes := 1048576
chunksDir := "/path/to/uploads/temp/3203610240-WildifeTactics"
/*
Generate an empty file
*/
f, err := os.Create("testfile.mp4")
if err != nil {
fmt.Printf("Error: %s", err)
}
defer f.Close()
//For every chunk, write it to the empty file. The number of iterations is determined from resumable.js
for i := 1; i <= 3055; i++ {
relativePath := fmt.Sprintf("%s%s%d", chunksDir, "/part", i)
fmt.Println("Chnk path: " + relativePath)
writeOffset := int64(chunkSizeInBytes * (i - 1))
if i == 1 {
writeOffset = 0
}
dat, err := ioutil.ReadFile(relativePath)
size, err := f.WriteAt(dat, writeOffset)
if err != nil {
fmt.Printf("Error: %s", err)
}
fmt.Printf("%d bytes written offset %d \n", size, writeOffset)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment