示例#1
0
func Get(path string, off, count int64, pred string) <-chan []byte {
	if len(path) > 0 && path[0] == '#' {
		rc := make(chan []byte)
		ioc, err := app.IOarg(path)
		if err != nil {
			close(rc, err)
			return rc
		}
		go func() {
			for x := range ioc {
				if b, ok := x.([]byte); ok {
					sok := rc <- b
					if !sok {
						close(ioc, cerror(rc))
						break
					}
				}
			}
			close(rc, cerror(ioc))
		}()
		return rc
	}
	path = app.AbsPath(path)
	_, trs, spaths, err := app.ResolveTree(path)
	if err != nil {
		rc := make(chan []byte)
		close(rc, err)
		return rc
	}
	return trs[0].Get(spaths[0], off, count, pred)
}
示例#2
0
// zx.Stat using the app ns and dot.
func Stat(path string) (zx.Dir, error) {
	if len(path) > 0 && path[0] == '#' {
		_, err := app.IOarg(path)
		if err != nil {
			return nil, fmt.Errorf("%s: %s", path, err)
		}
		d := zx.Dir{"path": path, "name": path,
			"upath": path, "type":"c"}
		return d, nil
	}
	path = app.AbsPath(path)
	_, trs, spaths, err := app.ResolveTree(path)
	if err != nil {
		return nil, err
	}
	return zx.Stat(trs[0], spaths[0])
}
示例#3
0
func Put(path string, d zx.Dir, off int64, dc <-chan []byte, pred string) chan zx.Dir {
	if len(path) > 0 && path[0] == '#' {
		rc := make(chan zx.Dir, 1)
		if d != nil {
			close(rc, fmt.Errorf("%s: %s", path, dbg.ErrPerm))
			return rc
		}
		ioc, err := app.IOarg(path)
		if err != nil {
			close(rc, err)
			return rc
		}
		go func() {
			for x := range dc {
				sok := ioc <- x
				if !sok {
					close(rc, cerror(rc))
					break
				}
			}
			d := zx.Dir{"path": path, "name": path,
				"upath": path, "type":"c"}
			rc <- d
			close(ioc, cerror(dc))
		}()
		return rc
	}
	path = app.AbsPath(path)
	_, trs, spaths, err := app.ResolveTree(path)
	if err != nil {
		rc := make(chan zx.Dir)
		close(rc, err)
		return rc
	}
	return trs[0].Put(spaths[0], d, off, dc, pred)
}