|
|
@ -34,7 +34,7 @@ func (b *Blob) GetBlobContent() (string, error) { |
|
|
|
return string(buf), nil |
|
|
|
return string(buf), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetBlobLineCount gets line count of lob as raw text
|
|
|
|
// GetBlobLineCount gets line count of the blob
|
|
|
|
func (b *Blob) GetBlobLineCount() (int, error) { |
|
|
|
func (b *Blob) GetBlobLineCount() (int, error) { |
|
|
|
reader, err := b.DataAsync() |
|
|
|
reader, err := b.DataAsync() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -42,10 +42,14 @@ func (b *Blob) GetBlobLineCount() (int, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
defer reader.Close() |
|
|
|
defer reader.Close() |
|
|
|
buf := make([]byte, 32*1024) |
|
|
|
buf := make([]byte, 32*1024) |
|
|
|
count := 0 |
|
|
|
count := 1 |
|
|
|
lineSep := []byte{'\n'} |
|
|
|
lineSep := []byte{'\n'} |
|
|
|
for { |
|
|
|
|
|
|
|
c, err := reader.Read(buf) |
|
|
|
c, err := reader.Read(buf) |
|
|
|
|
|
|
|
if c == 0 && err == io.EOF { |
|
|
|
|
|
|
|
return 0, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for { |
|
|
|
count += bytes.Count(buf[:c], lineSep) |
|
|
|
count += bytes.Count(buf[:c], lineSep) |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case err == io.EOF: |
|
|
|
case err == io.EOF: |
|
|
@ -53,6 +57,7 @@ func (b *Blob) GetBlobLineCount() (int, error) { |
|
|
|
case err != nil: |
|
|
|
case err != nil: |
|
|
|
return count, err |
|
|
|
return count, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
c, err = reader.Read(buf) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|