本文整理匯總了Golang中github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/rwvfs.FileSystem.Open方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem.Open方法的具體用法?Golang FileSystem.Open怎麽用?Golang FileSystem.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jingweno/ccat/Godeps/_workspace/src/sourcegraph/com/sourcegraph/rwvfs.FileSystem
的用法示例。
在下文中一共展示了FileSystem.Open方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readIndex
// readIndex calls x.Read with the index's backing file.
func readIndex(fs rwvfs.FileSystem, name string, x persistedIndex) (err error) {
vlog.Printf("%s: reading index...", name)
var f vfs.ReadSeekCloser
f, err = fs.Open(fmt.Sprintf(indexFilename, name))
if err != nil {
vlog.Printf("%s: failed to read index: %s.", name, err)
if os.IsNotExist(err) {
return &errIndexNotExist{name: name, err: err}
}
return err
}
defer func() {
err2 := f.Close()
if err == nil {
err = err2
}
}()
r, err := gzip.NewReader(f)
if err != nil {
return err
}
if err := x.Read(r); err != nil {
return err
}
if err := r.Close(); err != nil {
return err
}
vlog.Printf("%s: done reading index.", name)
return nil
}
示例2: testWrite
func testWrite(t *testing.T, fs rwvfs.FileSystem, path string) {
label := fmt.Sprintf("%T", fs)
w, err := fs.Create(path)
if err != nil {
t.Fatalf("%s: WriterOpen: %s", label, err)
}
input := []byte("qux")
_, err = w.Write(input)
if err != nil {
t.Fatalf("%s: Write: %s", label, err)
}
err = w.Close()
if err != nil {
t.Fatalf("%s: w.Close: %s", label, err)
}
var r io.ReadCloser
r, err = fs.Open(path)
if err != nil {
t.Fatalf("%s: Open: %s", label, err)
}
var output []byte
output, err = ioutil.ReadAll(r)
if err != nil {
t.Fatalf("%s: ReadAll: %s", label, err)
}
if !bytes.Equal(output, input) {
t.Errorf("%s: got output %q, want %q", label, output, input)
}
r, err = fs.Open(path)
if err != nil {
t.Fatalf("%s: Open: %s", label, err)
}
output, err = ioutil.ReadAll(r)
if err != nil {
t.Fatalf("%s: ReadAll: %s", label, err)
}
if !bytes.Equal(output, input) {
t.Errorf("%s: got output %q, want %q", label, output, input)
}
err = fs.Remove(path)
if err != nil {
t.Errorf("%s: Remove(%q): %s", label, path, err)
}
testPathDoesNotExist(t, label, fs, path)
}
示例3: openFetcherOrOpen
// openFetcher calls fs.OpenFetcher if it implemented the
// FetcherOpener interface; otherwise it calls fs.Open.
func openFetcherOrOpen(fs rwvfs.FileSystem, name string) (vfs.ReadSeekCloser, error) {
if fo, ok := fs.(rwvfs.FetcherOpener); ok {
return fo.OpenFetcher(name)
}
return fs.Open(name)
}