func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) {
	// Get the metadata
	meta, err := f.readMeta(id)
	if err != nil {
		f.logger.Printf("[ERR] snapshot: Failed to get meta data to open snapshot: %v", err)
		return nil, nil, err
	}

	// Open the state file
	statePath := filepath.Join(f.path, id, stateFilePath)
	fh, err := os.Open(statePath)
	if err != nil {
		f.logger.Printf("[ERR] snapshot: Failed to open state file: %v", err)
		return nil, nil, err
	}

	// Create a CRC64 hash
	stateHash := crc64.New(crc64.MakeTable(crc64.ECMA))

	// Compute the hash
	_, err = io.Copy(stateHash, fh)
	if err != nil {
		f.logger.Printf("[ERR] snapshot: Failed to read state file: %v", err)
		fh.Close()
		return nil, nil, err
	}

	// Verify the hash
	computed := stateHash.Sum(nil)
	if bytes.Compare(meta.CRC, computed) != 0 {
		f.logger.Printf("[ERR] snapshot: CRC checksum failed (stored: %v computed: %v)",
			meta.CRC, computed)
		fh.Close()
		return nil, nil, fmt.Errorf("CRC mismatch")
	}

	// Seek to the start
	if _, err := fh.Seek(0, 0); err != nil {
		f.logger.Printf("[ERR] snapshot: State file seek failed: %v", err)
		fh.Close()
		return nil, nil, err
	}

	// Return a buffered file
	buffered := &bufferedFile{
		bh: bufio.NewReader(fh),
		fh: fh,
	}

	return &meta.SnapshotMeta, buffered, nil
}
func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) {
	
	meta, err := f.readMeta(id)
	if err != nil {
		f.logger.Printf("[ERR] snapshot: Failed to get meta data to open snapshot: %v", err)
		return nil, nil, err
	}

	
	statePath := filepath.Join(f.path, id, stateFilePath)
	fh, err := os.Open(statePath)
	if err != nil {
		f.logger.Printf("[ERR] snapshot: Failed to open state file: %v", err)
		return nil, nil, err
	}

	
	stateHash := crc64.New(crc64.MakeTable(crc64.ECMA))

	
	_, err = io.Copy(stateHash, fh)
	if err != nil {
		f.logger.Printf("[ERR] snapshot: Failed to read state file: %v", err)
		fh.Close()
		return nil, nil, err
	}

	
	computed := stateHash.Sum(nil)
	if bytes.Compare(meta.CRC, computed) != 0 {
		f.logger.Printf("[ERR] snapshot: CRC checksum failed (stored: %v computed: %v)",
			meta.CRC, computed)
		fh.Close()
		return nil, nil, fmt.Errorf("CRC mismatch")
	}

	
	if _, err := fh.Seek(0, 0); err != nil {
		f.logger.Printf("[ERR] snapshot: State file seek failed: %v", err)
		fh.Close()
		return nil, nil, err
	}

	
	buffered := &bufferedFile{
		bh: bufio.NewReader(fh),
		fh: fh,
	}

	return &meta.SnapshotMeta, buffered, nil
}
func ( f * FileSnapshotStore ) Open ( id string ) ( * SnapshotMeta , io . ReadCloser , error ) { // Get the metadata meta , err := f . readMeta ( id ) if err != nil { f . logger . Printf ( " " , err ) return nil , nil , err } // Open the state file statePath := filepath . Join ( f . path , id , stateFilePath ) fh , err := os . Open ( statePath ) if err != nil { f . logger . Printf ( " " , err ) return nil , nil , err } // Create a CRC64 hash stateHash := crc64 . New ( crc64 . MakeTable ( crc64 . ECMA ) ) // Compute the hash _ , err = io . Copy ( stateHash , fh ) if err != nil { f . logger . Printf ( " " , err ) fh . Close ( ) return nil , nil , err } // Verify the hash computed := stateHash . Sum ( nil ) if bytes . Compare ( meta . CRC , computed ) != 0 { f . logger . Printf ( " " , meta . CRC , computed ) fh . Close ( ) return nil , nil , fmt . Errorf ( " " ) } // Seek to the start if _ , err := fh . Seek ( 0 , 0 ) ; err != nil { f . logger . Printf ( " " , err ) fh . Close ( ) return nil , nil , err } // Return a buffered file buffered := & bufferedFile { bh : bufio . NewReader ( fh ) , fh : fh , } return & meta . SnapshotMeta , buffered , nil }
// Open takes a snapshot ID and returns a ReadCloser for that snapshot.
Open takes a snapshot ID and returns a ReadCloser for that snapshot .