fix golint issues in core/filex (#485)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
const bufSize = 1024
|
||||
|
||||
// FirstLine returns the first line of the file.
|
||||
func FirstLine(filename string) (string, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
@@ -17,6 +18,7 @@ func FirstLine(filename string) (string, error) {
|
||||
return firstLine(file)
|
||||
}
|
||||
|
||||
// LastLine returns the last line of the file.
|
||||
func LastLine(filename string) (string, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
@@ -69,11 +71,11 @@ func lastLine(filename string, file *os.File) (string, error) {
|
||||
|
||||
if buf[n-1] == '\n' {
|
||||
buf = buf[:n-1]
|
||||
n -= 1
|
||||
n--
|
||||
} else {
|
||||
buf = buf[:n]
|
||||
}
|
||||
for n -= 1; n >= 0; n-- {
|
||||
for n--; n >= 0; n-- {
|
||||
if buf[n] == '\n' {
|
||||
return string(append(buf[n+1:], last...)), nil
|
||||
}
|
||||
|
||||
@@ -5,12 +5,15 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// OffsetRange represents a content block of a file.
|
||||
type OffsetRange struct {
|
||||
File string
|
||||
Start int64
|
||||
Stop int64
|
||||
}
|
||||
|
||||
// SplitLineChunks splits file into chunks.
|
||||
// The whole line are guaranteed to be split in the same chunk.
|
||||
func SplitLineChunks(filename string, chunks int) ([]OffsetRange, error) {
|
||||
info, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,8 +3,11 @@ package filex
|
||||
import "gopkg.in/cheggaaa/pb.v1"
|
||||
|
||||
type (
|
||||
// A Scanner is used to read lines.
|
||||
Scanner interface {
|
||||
// Scan checks if has remaining to read.
|
||||
Scan() bool
|
||||
// Text returns next line.
|
||||
Text() string
|
||||
}
|
||||
|
||||
@@ -14,6 +17,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// NewProgressScanner returns a Scanner with progress indicator.
|
||||
func NewProgressScanner(scanner Scanner, bar *pb.ProgressBar) Scanner {
|
||||
return &progressScanner{
|
||||
Scanner: scanner,
|
||||
|
||||
@@ -5,12 +5,14 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// A RangeReader is used to read a range of content from a file.
|
||||
type RangeReader struct {
|
||||
file *os.File
|
||||
start int64
|
||||
stop int64
|
||||
}
|
||||
|
||||
// NewRangeReader returns a RangeReader, which will read the range of content from file.
|
||||
func NewRangeReader(file *os.File, start, stop int64) *RangeReader {
|
||||
return &RangeReader{
|
||||
file: file,
|
||||
@@ -19,6 +21,7 @@ func NewRangeReader(file *os.File, start, stop int64) *RangeReader {
|
||||
}
|
||||
}
|
||||
|
||||
// Read reads the range of content into p.
|
||||
func (rr *RangeReader) Read(p []byte) (n int, err error) {
|
||||
stat, err := rr.file.Stat()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user