Skip to content

Commit

Permalink
fix read dump file imcompletely
Browse files Browse the repository at this point in the history
  • Loading branch information
medcl committed Oct 13, 2016
1 parent a46c13e commit 88c6341
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 11 additions & 5 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"bufio"
"encoding/json"
"io"
)

func checkFileIsExist(filename string) (bool) {
Expand All @@ -40,13 +41,18 @@ func (m *Migrator) NewFileReadWorker(pb *pb.ProgressBar, wg *sync.WaitGroup) {
log.Error(err)
return
}
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)

defer f.Close()
r := bufio.NewReader(f)
lineCount := 0
for scanner.Scan() {
lineCount++
for{
line,err := r.ReadString('\n')
if io.EOF == err || nil != err{
break
}
lineCount += 1
js := map[string]interface{}{}
line := scanner.Text()

//log.Trace("reading file,",lineCount,",", line)
err = json.Unmarshal([]byte(line), &js)
if(err!=nil){
Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
goflags "github.com/jessevdk/go-flags"
pb "gopkg.in/cheggaaa/pb.v1"
"os"
"io"
)

func main() {
Expand Down Expand Up @@ -125,10 +126,15 @@ func main() {
return
}
//get file lines
fileScanner := bufio.NewScanner(f)
lineCount := 0
for fileScanner.Scan() {
lineCount++
defer f.Close()
r := bufio.NewReader(f)
for{
_,err := r.ReadString('\n')
if io.EOF == err || nil != err{
break
}
lineCount += 1
}
log.Trace("file line,", lineCount)
fetchBar = pb.New(lineCount).Prefix("Read")
Expand Down

0 comments on commit 88c6341

Please sign in to comment.