本文整理匯總了Golang中github.com/cznic/fileutil.IsEOF函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsEOF函數的具體用法?Golang IsEOF怎麽用?Golang IsEOF使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsEOF函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WriteAt
func (f *bitFiler) WriteAt(b []byte, off int64) (n int, err error) {
off0 := off
pgI := off >> bfBits
pgO := int(off & bfMask)
n = len(b)
rem := n
var nc int
for rem != 0 {
pg := f.m[pgI]
if pg == nil {
pg = &bitPage{}
if f.parent != nil {
_, err = f.parent.ReadAt(pg.data[:], off&^bfMask)
if err != nil && !fileutil.IsEOF(err) {
return
}
err = nil
}
f.m[pgI] = pg
}
nc = copy(pg.data[pgO:], b)
pgI++
pg.dirty = true
for i := pgO; i < pgO+nc; i++ {
pg.flags[i>>3] |= bitmask[i&7]
}
pgO = 0
rem -= nc
b = b[nc:]
off += int64(nc)
}
f.size = mathutil.MaxInt64(f.size, off0+int64(n))
return
}
示例2: Read
// Read returns the next Source ScannerRune.
func (s *Source) Read() (r ScannerRune) {
for {
r.Position = s.Position()
r.Rune, r.Size, r.Err = s.tos.reader.ReadRune()
if r.Err == nil || !fileutil.IsEOF(r.Err) {
p := &s.tos.position
p.Offset += r.Size
if r.Rune != '\n' {
p.Column++
} else {
p.Line++
p.Column = 1
}
return
}
// err == os.EOF, try parent source
if sp := len(s.stack) - 1; sp >= 0 {
s.tos = s.stack[sp]
s.stack = s.stack[:sp]
} else {
r.Rune, r.Size = 0, 0
return
}
}
}
示例3: getc
func (l *lex) getc() (b byte, err error) {
switch b = l.current; b {
case 0:
break
case '\n':
l.line++
l.column = 0
fallthrough
default:
l.column++
l.buf = append(l.buf, b)
}
l.current = 0
b, err = l.src.ReadByte()
if err != nil {
b = 0
if !fileutil.IsEOF(err) {
return
}
err = nil
}
l.ofs++
l.current = b
return
}
示例4: ReadAt
func (f *bitFiler) ReadAt(b []byte, off int64) (n int, err error) {
avail := f.size - off
pgI := off >> bfBits
pgO := int(off & bfMask)
rem := len(b)
if int64(rem) >= avail {
rem = int(avail)
err = io.EOF
}
for rem != 0 && avail > 0 {
pg := f.m[pgI]
if pg == nil {
pg = &bitPage{}
pg.pdata = buffer.CGet(bfSize)
pg.data = *pg.pdata
if f.parent != nil {
_, err = f.parent.ReadAt(pg.data, off&^bfMask)
if err != nil && !fileutil.IsEOF(err) {
return
}
err = nil
}
f.m[pgI] = pg
}
nc := copy(b[:mathutil.Min(rem, bfSize)], pg.data[pgO:])
pgI++
pgO = 0
rem -= nc
n += nc
b = b[nc:]
off += int64(nc)
}
return
}
示例5: WriteAt
func (f *bitFiler) WriteAt(b []byte, off int64) (n int, err error) {
off0 := off
pgI := off >> bfBits
pgO := int(off & bfMask)
n = len(b)
rem := n
var nc int
for rem != 0 {
pg := f.m[pgI]
if pg == nil {
pg = &bitPage{}
pg.pdata = buffer.CGet(bfSize)
pg.data = *pg.pdata
if f.parent != nil {
_, err = f.parent.ReadAt(pg.data, off&^bfMask)
if err != nil && !fileutil.IsEOF(err) {
return
}
err = nil
}
f.m[pgI] = pg
}
nc = copy(pg.data[pgO:], b)
pgI++
pg.dirty = true
pgO = 0
rem -= nc
b = b[nc:]
off += int64(nc)
}
f.size = mathutil.MaxInt64(f.size, off0+int64(n))
return
}
示例6: readFrom
func readFrom(f Interface, r io.Reader) (n int64, err error) {
f.Truncate(0)
p := buffer.Get(copyBufSize)
b := *p
defer buffer.Put(p)
var off int64
var werr error
for {
rn, rerr := r.Read(b)
if rn != 0 {
_, werr = f.WriteAt(b[:rn], off)
n += int64(rn)
off += int64(rn)
}
if rerr != nil {
if !fileutil.IsEOF(rerr) {
err = rerr
}
break
}
if werr != nil {
err = werr
break
}
}
return n, err
}
示例7: writeTo
func writeTo(f Interface, w io.Writer) (n int64, err error) {
p := buffer.Get(copyBufSize)
b := *p
defer buffer.Put(p)
var off int64
var werr error
for {
rn, rerr := f.ReadAt(b, off)
if rn != 0 {
_, werr = w.Write(b[:rn])
n += int64(rn)
off += int64(rn)
}
if rerr != nil {
if !fileutil.IsEOF(rerr) {
err = rerr
}
break
}
if werr != nil {
err = werr
break
}
}
return n, err
}
示例8: WriteTo
// WriteTo is a helper to copy/persist File's content to w. If w is also
// an io.WriterAt then WriteTo may attempt to _not_ write any big, for some
// value of big, runs of zeros, i.e. it will attempt to punch holes, where
// possible, in `w` if that happens to be a freshly created or to zero length
// truncated OS file. 'n' reports the number of bytes written to 'w'.
func (f *File) WriteTo(w io.Writer) (n int64, err error) {
var (
b [pgSize]byte
wn, rn int
off int64
rerr error
)
if wa, ok := w.(io.WriterAt); ok {
fsize, err := f.Size()
if err != nil {
return n, err
}
lastPgI := fsize >> pgBits
for pgI := int64(0); pgI <= lastPgI; pgI++ {
sz := pgSize
if pgI == lastPgI {
sz = int(fsize & pgMask)
}
v, err := (*Array)(f).Get(pgI)
if err != nil {
return n, err
}
pg, _ := v.([]byte)
if len(pg) != 0 {
wn, err = wa.WriteAt(pg[:sz], off)
if err != nil {
return n, err
}
n += int64(wn)
off += int64(sz)
if wn != sz {
return n, io.ErrShortWrite
}
}
}
return n, err
}
var werr error
for rerr == nil {
if rn, rerr = f.ReadAt(b[:], off); rn != 0 {
off += int64(rn)
if wn, werr = w.Write(b[:rn]); werr != nil {
return n, werr
}
n += int64(wn)
}
}
if !fileutil.IsEOF(rerr) {
err = rerr
}
return
}
示例9: WriteTo
// WriteTo is a helper to copy/persist MemFiler's content to w. If w is also
// an io.WriterAt then WriteTo may attempt to _not_ write any big, for some
// value of big, runs of zeros, i.e. it will attempt to punch holes, where
// possible, in `w` if that happens to be a freshly created or to zero length
// truncated OS file. 'n' reports the number of bytes written to 'w'.
func (f *MemFiler) WriteTo(w io.Writer) (n int64, err error) {
var (
b [pgSize]byte
wn, rn int
off int64
rerr error
)
if wa, ok := w.(io.WriterAt); ok {
lastPgI := f.size >> pgBits
for pgI := int64(0); pgI <= lastPgI; pgI++ {
sz := pgSize
if pgI == lastPgI {
sz = int(f.size & pgMask)
}
pg := f.m[pgI]
if pg != nil {
wn, err = wa.WriteAt(pg[:sz], off)
if err != nil {
return
}
n += int64(wn)
off += int64(sz)
if wn != sz {
return n, io.ErrShortWrite
}
}
}
return
}
var werr error
for rerr == nil {
if rn, rerr = f.ReadAt(b[:], off); rn != 0 {
off += int64(rn)
if wn, werr = w.Write(b[:rn]); werr != nil {
return n, werr
}
n += int64(wn)
}
}
if !fileutil.IsEOF(rerr) {
err = rerr
}
return
}
示例10: getc
func (l *lex) getc(c byte) byte {
if c != 0 {
l.buf = append(l.buf, c)
}
if b, err := l.src.ReadByte(); err == nil {
l.peek = b
if b == '\n' {
l.begin(sc_LINE_START)
l.line++
l.column = 1
} else {
l.column++
}
return b
} else {
if fileutil.IsEOF(err) {
l.peek = 0
return 0
}
panic(err)
}
}
示例11: Scan
// Scan scans a pcat formatted text file from src, assuming file name is
// 'name'. Handler 'handler' is called for every Record found in src. If
// handler returns false the scanning process is aborted and Scan returns err
// == nil. If there is any error detected while scanning then the scanning is
// aborted as well and the error is returned.
func Scan(name string, src io.ByteReader, handler func(*Record) bool) (err error) {
l := newLex(src)
defer func() {
if e := recover(); e != nil {
x, ok := e.(error)
if !ok || !fileutil.IsEOF(x) {
err = fmt.Errorf("%s:%d:%d %s", name, l.line, l.column, e)
}
}
}()
for {
var r *Record
switch r, err = l.scan(); {
case err != nil:
panic(err)
case r == nil || !handler(r):
return
}
}
panic("unreachable")
}
示例12: ReadFrom
// ReadFrom is a helper to populate MemFiler's content from r. 'n' reports the
// number of bytes read from 'r'.
func (f *MemFiler) ReadFrom(r io.Reader) (n int64, err error) {
if err = f.Truncate(0); err != nil {
return
}
var (
b [pgSize]byte
rn int
off int64
)
var rerr error
for rerr == nil {
if rn, rerr = r.Read(b[:]); rn != 0 {
f.WriteAt(b[:rn], off)
off += int64(rn)
n += int64(rn)
}
}
if !fileutil.IsEOF(rerr) {
err = rerr
}
return
}
示例13: TestseekLast
func TestseekLast(t *testing.T) {
bt := NewBTree(nil)
enum, err := bt.seekFirst()
if !fileutil.IsEOF(err) {
t.Fatal(err)
}
bt.Set([]byte("a"), []byte("b"))
enum, err = bt.seekFirst()
if err != nil {
t.Fatal(err)
}
err = enum.prev()
if !fileutil.IsEOF(err) {
t.Fatal(err)
}
err = enum.next()
if !fileutil.IsEOF(err) {
t.Fatal(err)
}
k, v, err := enum.current()
if err != nil {
t.Fatal(err)
}
if string(k) != "a" || string(v) != "b" {
t.Fatal(k, v)
}
bt.Set([]byte("c"), []byte("d"))
enum, err = bt.seekLast()
if err != nil {
t.Fatal(err)
}
err = enum.next()
if !fileutil.IsEOF(err) {
t.Fatal(err)
}
k, v, err = enum.current()
if err != nil {
t.Fatal(err)
}
if string(k) != "c" || string(v) != "d" {
t.Fatal(k, v)
}
err = enum.prev()
if err != nil {
t.Fatal(err)
}
k, v, err = enum.current()
if err != nil {
t.Fatal(err)
}
if string(k) != "a" || string(v) != "b" {
t.Fatal(k, v)
}
}
示例14: TestbTreePrev
func TestbTreePrev(t *testing.T) {
N := int64(*testN)
tree := NewBTree(nil)
enum, _, err := tree.seek(enc8(0))
if err != nil {
t.Fatal(err)
}
if _, _, err = enum.current(); !fileutil.IsEOF(err) {
t.Fatal(err)
}
if err = enum.next(); !fileutil.IsEOF(err) {
t.Fatal(err)
}
if err = enum.prev(); !fileutil.IsEOF(err) {
t.Fatal(err)
}
// Fill
for i := int64(1); i <= N; i++ {
tree.Set(enc8(10*i), enc8(10*i+1))
}
var eq bool
enum, eq, err = tree.seek(enc8(0))
if err != nil {
t.Fatal(err)
}
if eq {
t.Fatal(eq)
}
// index: 0
if _, _, err = enum.current(); err != nil {
t.Fatal(err)
}
if err = enum.prev(); !fileutil.IsEOF(err) {
t.Fatal(err)
}
enum, eq, err = tree.seek(enc8(N * 10))
if err != nil {
t.Fatal(err)
}
if !eq {
t.Fatal(eq)
}
// index: N-1
if _, _, err = enum.current(); err != nil {
t.Fatal(err)
}
if err = enum.prev(); N > 1 && err != nil {
t.Fatal(err)
}
enum, eq, err = tree.seek(enc8(N*10 + 1))
if err != nil {
t.Fatal(err)
}
if eq {
t.Fatal(eq)
}
// index: N
if _, _, err = enum.current(); !fileutil.IsEOF(err) {
t.Fatal(err)
}
if err = enum.prev(); err != nil {
t.Fatal(err)
}
enum, _, err = tree.seek(enc8(N * 10))
if err != nil {
t.Fatal(err)
}
for i := N; i >= 1; i-- {
expKey, expValue := enc8(10*i), enc8(10*i+1)
k, v, err := enum.current()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(k, expKey) {
t.Fatalf("%d k|% x| expK|% x| %s\n", i, k, expKey, tree.root.String(tree.store))
}
if !bytes.Equal(v, expValue) {
t.Fatal(i)
//.........這裏部分代碼省略.........
示例15: TestSeekPrev
func TestSeekPrev(t *testing.T) {
// seeking within 3 keys: 10, 20, 30
table := []struct {
k int
hit bool
keys []int
}{
{5, false, []int{10}},
{10, true, []int{10}},
{15, false, []int{20, 10}},
{20, true, []int{20, 10}},
{25, false, []int{30, 20, 10}},
{30, true, []int{30, 20, 10}},
{35, false, []int{}},
}
for i, test := range table {
down := test.keys
db, err := CreateMem(opts())
if err != nil {
t.Fatal(i, err)
}
if err := db.Set(n2b(10), n2b(100)); err != nil {
t.Fatal(i, err)
}
if err := db.Set(n2b(20), n2b(200)); err != nil {
t.Fatal(i, err)
}
if err := db.Set(n2b(30), n2b(300)); err != nil {
t.Fatal(i, err)
}
for brokenSerial := 0; brokenSerial < 16; brokenSerial++ {
en, hit, err := db.Seek(n2b(test.k))
if err != nil {
t.Fatal(err)
}
if g, e := hit, test.hit; g != e {
t.Fatal(i, g, e)
}
j := 0
for {
if brokenSerial&(1<<uint(j)) != 0 {
if err := db.Set(n2b(20), n2b(200)); err != nil {
t.Fatal(i, err)
}
}
k, v, err := en.Prev()
if err != nil {
if !fileutil.IsEOF(err) {
t.Fatal(i, err)
}
break
}
if g, e := len(k), 8; g != e {
t.Fatal(i, g, e)
}
if j >= len(down) {
t.Fatal(i, j, brokenSerial)
}
if g, e := b2n(k), down[j]; g != e {
t.Fatal(i, j, brokenSerial, g, e)
}
if g, e := len(v), 8; g != e {
t.Fatal(i, g, e)
}
if g, e := b2n(v), 10*down[j]; g != e {
t.Fatal(i, g, e)
}
j++
}
if g, e := j, len(down); g != e {
t.Fatal(i, j, g, e)
}
}
}
}