bytes.go
func BytesHead(data []byte, numLines int) (lines []string, rest []byte) {
	if numLines <= 0 {
		panic("numLines must be greater than zero")
	}
	lines = make([]string, 0, numLines)
	begin := 0
	for i := range data {
		if data[i] == '\n' {
			end := i
			if i > 0 && data[i-1] == '\r' {
				end--
			}
			lines = append(lines, string(data[begin:end]))
			begin = i + 1
			if len(lines) == numLines {
				break
			}
		}
	}
	if len(lines) != numLines {
		lines = append(lines, string(data[begin:]))
		begin = len(data)
	}
	return lines, data[begin:]
}
func BytesHead(data []byte, numLines int) (lines []string, rest []byte) {
	if numLines <= 0 {
		panic("numLines must be greater than zero")
	}
	lines = make([]string, 0, numLines)
	begin := 0
	for i := range data {
		if data[i] == '\n' {
			end := i
			if i > 0 && data[i-1] == '\r' {
				end--
			}
			lines = append(lines, string(data[begin:end]))
			begin = i + 1
			if len(lines) == numLines {
				break
			}
		}
	}
	if len(lines) != numLines {
		lines = append(lines, string(data[begin:]))
		begin = len(data)
	}
	return lines, data[begin:]
}
func BytesHead ( data [ ] byte , numLines int ) ( lines [ ] string , rest [ ] byte ) { if numLines <= 0 { panic ( " " ) } lines = make ( [ ] string , 0 , numLines ) begin := 0 for i := range data { if data [ i ] == '\n' { end := i if i > 0 && data [ i - 1 ] == '\r' { end -- } lines = append ( lines , string ( data [ begin : end ] ) ) begin = i + 1 if len ( lines ) == numLines { break } } } if len ( lines ) != numLines { lines = append ( lines , string ( data [ begin : ] ) ) begin = len ( data ) } return lines , data [ begin : ] }
// BytesHead returns at most numLines from data starting at the beginning.
// A slice of the remaining data is returned as rest.
// \n is used to detect line ends, a preceding \r will be stripped away.
// BytesHead resembles the Unix head command.
BytesHead returns at most numLines from data starting at the beginning . A slice of the remaining data is returned as rest . \ n is used to detect line ends a preceding \ r will be stripped away . BytesHead resembles the Unix head command .