Exemplo n.º 1
0
func ListBlock(apiClient drive.APIClient) ([]*drive.BlockInfo, error) {
	blockInfos, err := apiClient.ListBlock(
		context.Background(),
		&drive.ListBlockRequest{},
	)
	if err != nil {
		return nil, err
	}
	return blockInfos.BlockInfo, nil
}
Exemplo n.º 2
0
func PutBlock(apiClient drive.APIClient, reader io.Reader) (*drive.BlockRefs, error) {
	putBlockClient, err := apiClient.PutBlock(context.Background())
	if err != nil {
		return nil, err
	}
	if _, err := io.Copy(protostream.NewStreamingBytesWriter(putBlockClient), reader); err != nil {
		return nil, err
	}
	return putBlockClient.CloseAndRecv()
}
Exemplo n.º 3
0
func InspectBlock(apiClient drive.APIClient, hash string) (*drive.BlockInfo, error) {
	blockInfo, err := apiClient.InspectBlock(
		context.Background(),
		&drive.InspectBlockRequest{
			Block: &drive.Block{
				Hash: hash,
			},
		},
	)
	if err != nil {
		return nil, err
	}
	return blockInfo, nil
}
Exemplo n.º 4
0
func GetBlock(apiClient drive.APIClient, hash string, offsetBytes uint64) (io.Reader, error) {
	apiGetBlockClient, err := apiClient.GetBlock(
		context.Background(),
		&drive.GetBlockRequest{
			Block: &drive.Block{
				Hash: hash,
			},
			OffsetBytes: offsetBytes,
		},
	)
	if err != nil {
		return nil, err
	}
	return protostream.NewStreamingBytesReader(apiGetBlockClient), nil
}