Example #1
0
func PushDiff(replicaAPIClient pfs.ReplicaAPIClient, repoName string, commitID string, shard uint64, reader io.Reader) (retErr error) {
	pushDiffClient, err := replicaAPIClient.PushDiff(context.Background())
	if err != nil {
		return err
	}
	defer func() {
		if _, err := pushDiffClient.CloseAndRecv(); err != nil && retErr != nil {
			retErr = err
		}
	}()
	request := pfs.PushDiffRequest{
		Commit: &pfs.Commit{
			Repo: &pfs.Repo{
				Name: repoName,
			},
			Id: commitID,
		},
		Shard: shard,
	}
	for {
		value := make([]byte, chunkSize)
		size, err := reader.Read(value)
		if err != nil {
			if err == io.EOF {
				break
			}
			return err
		}
		request.Value = value[0:size]
		if err = pushDiffClient.Send(&request); err != nil {
			return err
		}
	}
	return nil
}
Example #2
0
func PullDiff(replicaAPIClient pfs.ReplicaAPIClient, repoName string, commitID string, shard uint64, writer io.Writer) error {
	apiPullDiffClient, err := replicaAPIClient.PullDiff(
		context.Background(),
		&pfs.PullDiffRequest{
			Commit: &pfs.Commit{
				Repo: &pfs.Repo{
					Name: repoName,
				},
				Id: commitID,
			},
			Shard: shard,
		},
	)
	if err != nil {
		return err
	}
	if err := protostream.WriteFromStreamingBytesClient(apiPullDiffClient, writer); err != nil {
		return err
	}
	return nil
}