func (sr *StoreRoot) bytesFromFile(name string, maxlen int64) ([]byte, int64, error) {

    var b []byte
    var fsize int64

    rootdir := sr.GetDirectory()

    fsn, err := rootdir.Child(name)
    if err != nil {
        return b, fsize, err
    }

    fi := fsn.(*mfs.File)

    if fi.Type() != mfs.TFile {
        return b, fsize, fmt.Errorf("expected repoprops file, invalid type %v", fi.Type())
    }

    wfd, err := fi.Open(mfs.OpenReadWrite, true)
    if err != nil {
        return b, fsize, err
    }
    defer wfd.Close()


    fsize, err = fi.Size()
    if err != nil {
        return b, fsize, err
    }

    // seek back to beginning
    ns, err := wfd.Seek(0, io.SeekStart)
    if err != nil {
        return b, fsize, err
    }

    if ns != 0 {
        return b, fsize, fmt.Errorf("failed to seek to beginning.")
    }

    // read back bytes we wrote
    b = make([]byte, maxlen)
    _, err = wfd.Read(b)
    if err != nil {
        return b, fsize, err
    }

    return b, fsize, nil
}
// return up to specified number of bytes from file, and the file size
// internal function mostly intended for validation testing
return up to specified number of bytes from file, and the file size
internal function mostly intended for validation testing
// return up to specified number of bytes from file and the file size // internal function mostly intended for validation testing
func (sr *StoreRoot) bytesFromFile(name string, maxlen int64) ([]byte, int64, error) {
    var b []byte
    var fsize int64
    rootdir := sr.GetDirectory()
    fsn, err := rootdir.Child(name)
    if err != nil {
        return b, fsize, err
    }
    fi := fsn.(*mfs.File)
    if fi.Type() != mfs.TFile {
        return b, fsize, fmt.Errorf("expected repoprops file, invalid type %v", fi.Type())
    }
    wfd, err := fi.Open(mfs.OpenReadWrite, true)
    if err != nil {
        return b, fsize, err
    }
    defer wfd.Close()
    fsize, err = fi.Size()
    if err != nil {
        return b, fsize, err
    }
    ns, err := wfd.Seek(0, io.SeekStart)
    if err != nil {
        return b, fsize, err
    }
    if ns != 0 {
        return b, fsize, fmt.Errorf("failed to seek to beginning.")
    }
    b = make([]byte, maxlen)
    _, err = wfd.Read(b)
    if err != nil {
        return b, fsize, err
    }
    return b, fsize, nil
}
func ( sr * StoreRoot ) bytesFromFile ( name string , maxlen int64 ) ( [ ] byte , int64 , error ) { var b [ ] byte var fsize int64 rootdir := sr . GetDirectory ( ) fsn , err := rootdir . Child ( name ) if err != nil { return b , fsize , err } fi := fsn . ( * mfs . File ) if fi . Type ( ) != mfs . TFile { return b , fsize , fmt . Errorf ( " " , fi . Type ( ) ) } wfd , err := fi . Open ( mfs . OpenReadWrite , true ) if err != nil { return b , fsize , err } defer wfd . Close ( ) fsize , err = fi . Size ( ) if err != nil { return b , fsize , err } ns , err := wfd . Seek ( 0 , io . SeekStart ) if err != nil { return b , fsize , err } if ns != 0 { return b , fsize , fmt . Errorf ( " " ) } b = make ( [ ] byte , maxlen ) _ , err = wfd . Read ( b ) if err != nil { return b , fsize , err } return b , fsize , nil }
return up to specified number of bytes from file, and the file size
internal function mostly intended for validation testing
return up to specified number of bytes from file and the file size internal function mostly intended for validation testing
// seek back to beginning // read back bytes we wrote