Created
October 7, 2015 17:03
-
-
Save klauspost/cc7e7de04a9c5825787c to your computer and use it in GitHub Desktop.
Split a file similar to how Total Commander does it (No CRC).
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 ( | |
"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