Пример #1
0
func (file *RegularFile) scan(fileSystem *FileSystem, parentName string) error {
	myPathName := path.Join(parentName, file.Name)
	f, err := os.Open(myPathName)
	if err != nil {
		return err
	}
	reader := fsrateio.NewReader(f, fileSystem.ctx)
	hash := sha512.New()
	io.Copy(hash, reader)
	f.Close()
	copy(file.inode.Hash[:], hash.Sum(nil))
	fileSystem.HashCount++
	return nil
}
Пример #2
0
// Benchmark the read speed of the underlying block device for a given file.
func main() {
	pathname := "/"
	if len(os.Args) == 2 {
		pathname = os.Args[1]
	}
	bytesPerSecond, blocksPerSecond, err := fsbench.GetReadSpeed(pathname)
	if err != nil {
		fmt.Printf("Error! %s\n", err)
		return
	}
	ctx := fsrateio.NewContext(bytesPerSecond, blocksPerSecond)
	fmt.Println(ctx)
	var file *os.File
	file, err = os.Open(pathname)
	if err != nil {
		fmt.Printf("Error! %s\n", err)
		return
	}
	rd := bufio.NewReader(fsrateio.NewReader(file, ctx))
	buffer := make([]byte, 65536)
	timeStart := time.Now()
	tread := 0
	for {
		n := 0
		n, err = rd.Read(buffer)
		if n < 1 && err == io.EOF {
			break
		}
		if err != nil {
			fmt.Printf("Error! %s\n", err)
			return
		}
		tread += n
	}
	bytesPerSecond = uint64(float64(tread) / time.Since(timeStart).Seconds())
	fmt.Printf("%s/s\n", fsrateio.FormatBytes(bytesPerSecond))
}