本文整理汇总了Golang中github.com/spf13/afero.File类的典型用法代码示例。如果您正苦于以下问题:Golang File类的具体用法?Golang File怎么用?Golang File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: read
// read reads blocks of 4096 bytes from the File, sending lines to the
// channel as it encounters newlines. If EOF is encountered, the partial line
// is returned to be concatenated with on the next call.
func (t *Tailer) read(f afero.File, partialIn string) (partialOut string, err error) {
partial := partialIn
b := make([]byte, 0, 4096)
for {
n, err := f.Read(b[:cap(b)])
b = b[:n]
if err != nil {
return partial, err
}
for i, width := 0, 0; i < len(b) && i < n; i += width {
var rune rune
rune, width = utf8.DecodeRune(b[i:])
switch {
case rune != '\n':
partial += string(rune)
default:
// send off line for processing
t.lines <- partial
// reset accumulator
partial = ""
}
}
}
}
开发者ID:wrouesnel,项目名称:mtail,代码行数:28,代码来源:tail.go
示例2: registerDirs
func (m *MemS3Fs) registerDirs(f afero.File) {
var x = f.Name()
for x != "/" {
f := m.registerWithParent(f)
if f == nil {
break
}
x = f.Name()
}
}
开发者ID:pombredanne,项目名称:af3ro,代码行数:10,代码来源:fs.go
示例3: readForever
func (t *Tailer) readForever(f afero.File) {
var err error
partial := ""
for {
partial, err = t.read(f, partial)
// We want to exit at EOF, because the FD has been closed.
if err != nil {
glog.Infof("%s: %s", err, f.Name())
return
}
}
}
开发者ID:wrouesnel,项目名称:mtail,代码行数:12,代码来源:tail.go
示例4: findParent
func (m *MemS3Fs) findParent(f afero.File) afero.File {
dirs, _ := path.Split(f.Name())
if len(dirs) > 1 {
_, parent := path.Split(path.Clean(dirs))
if len(parent) > 0 {
pfile, err := m.Open(parent)
if err != nil {
return pfile
}
}
}
return nil
}
开发者ID:pombredanne,项目名称:af3ro,代码行数:13,代码来源:fs.go
示例5: registerWithParent
func (m *MemS3Fs) registerWithParent(f afero.File) afero.File {
if f == nil {
return nil
}
parent := m.findParent(f)
if parent != nil {
pmem := parent.(*InMemoryFile)
pmem.memDir.Add(f)
} else {
pdir := filepath.Dir(path.Clean(f.Name()))
m.Mkdir(pdir, 0777)
}
return parent
}
开发者ID:pombredanne,项目名称:af3ro,代码行数:14,代码来源:fs.go
示例6: checkSize
func checkSize(t *testing.T, f afero.File, size int64) {
dir, err := f.Stat()
if err != nil {
t.Fatalf("Stat %q (looking for size %d): %s", f.Name(), size, err)
}
if dir.Size() != size {
t.Errorf("Stat %q: size %d want %d", f.Name(), dir.Size(), size)
}
}
开发者ID:pombredanne,项目名称:af3ro,代码行数:9,代码来源:fs_test.go
示例7: startNewFile
func (t *Tailer) startNewFile(f afero.File, seekStart bool) error {
fi, err := f.Stat()
if err != nil {
// Stat failed, log error and return.
logErrors.Add(f.Name(), 1)
return fmt.Errorf("Failed to stat %q: %s", f.Name(), err)
}
switch m := fi.Mode(); {
case m&os.ModeType == 0:
if seekStart {
f.Seek(0, os.SEEK_SET)
} else {
f.Seek(0, os.SEEK_END)
}
err = t.w.Add(f.Name())
if err != nil {
return fmt.Errorf("Adding a change watch failed on %q: %s", f.Name(), err)
}
// In case the new log has been written to already, attempt to read the
// first lines.
t.partials[f.Name()], err = t.read(f, "")
if err != nil {
if err == io.EOF {
// Don't worry about EOF on first read, that's expected.
break
}
return err
}
case m&os.ModeType == os.ModeNamedPipe:
go t.readForever(f)
default:
return fmt.Errorf("Can't open files with mode %v: %s", m&os.ModeType, f.Name())
}
t.filesLock.Lock()
t.files[f.Name()] = f
t.filesLock.Unlock()
glog.Infof("Tailing %s", f.Name())
return nil
}
开发者ID:wrouesnel,项目名称:mtail,代码行数:40,代码来源:tail.go
示例8: Remove
func (m MemDirMap) Remove(f afero.File) { delete(m, f.Name()) }
开发者ID:pombredanne,项目名称:af3ro,代码行数:1,代码来源:fs.go
示例9: Add
func (m MemDirMap) Add(f afero.File) { m[f.Name()] = f }
开发者ID:pombredanne,项目名称:af3ro,代码行数:1,代码来源:fs.go
注:本文中的github.com/spf13/afero.File类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论