Skip to content

Instantly share code, notes, and snippets.

@klauspost
Created October 7, 2015 17:03
Show Gist options
  • Save klauspost/cc7e7de04a9c5825787c to your computer and use it in GitHub Desktop.
Save klauspost/cc7e7de04a9c5825787c to your computer and use it in GitHub Desktop.
Split a file similar to how Total Commander does it (No CRC).
package main
import (
"fmt"
"io"
"os"
"path/filepath"
)
const (
each = 1073741824
)
func main() {
f, err := os.Open("shared-finished.zpaq")
if err != nil {
panic(err)
}
at := 650
f.Seek(int64((at-1)*each), os.SEEK_CUR)
defer f.Close()
for {
name := fmt.Sprintf("e:\\up\\%d00-%d99\\shared-finished.%03d", at/100, at/100, at)
err = os.MkdirAll(filepath.Dir(name), 0666)
if err != nil {
panic(err)
}
out, err := os.Create(name)
if err != nil {
panic(err)
}
n, err := io.CopyN(out, f, each)
if err != nil && err != io.EOF {
panic(err)
}
out.Close()
if err == io.EOF {
break
}
if n != each {
panic("short copy")
}
fmt.Println("Copied segment", at)
at++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment