mirror of https://github.com/schollz/croc.git
SplitFile will not create an empty file anymore. Also files created by tests will be removed.
This commit is contained in:
parent
33de3066d5
commit
60cb509ff9
9
utils.go
9
utils.go
|
@ -36,7 +36,7 @@ func CatFiles(files []string, outfile string, remove bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SplitFile
|
||||
// SplitFile creates a bunch of smaller files with the data from source splited into them
|
||||
func SplitFile(fileName string, numPieces int) (err error) {
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
|
@ -62,10 +62,13 @@ func SplitFile(fileName string, numPieces int) (err error) {
|
|||
for {
|
||||
n, err := file.Read(buf)
|
||||
out.Write(buf[:n])
|
||||
bytesRead += n
|
||||
if err == io.EOF {
|
||||
// If written bytes count is smaller than lenght of buffer
|
||||
// then we don't create one more empty file
|
||||
if err == io.EOF || n < len(buf) {
|
||||
break
|
||||
}
|
||||
bytesRead += n
|
||||
|
||||
if bytesRead >= bytesPerPiece {
|
||||
// Close file and open a new one
|
||||
out.Close()
|
||||
|
|
|
@ -12,5 +12,4 @@ func TestSplitFile(t *testing.T) {
|
|||
}
|
||||
os.Remove("README.md.0")
|
||||
os.Remove("README.md.1")
|
||||
os.Remove("README.md.2")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue