~rockorager/go-jmap-devel

go-jmap: client: allow upload/download with a context v1 PROPOSED

Robin Jarry: 1
 client: allow upload/download with a context

 1 files changed, 20 insertions(+), 0 deletions(-)
Tim Culverhouse, Feb 13, 2024 at 03:16:
Next
Tim Culverhouse, Feb 15, 2024 at 18:38:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rockorager/go-jmap-devel/patches/49420/mbox | git am -3
Learn more about email & git

[PATCH go-jmap] client: allow upload/download with a context Export this patch

Add new UploadWithContext and DownloadWithContext methods to
jmap.Client to allow cancelling these requests.

Signed-off-by: Robin Jarry <robin@jarry.cc>
---
 client.go | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/client.go b/client.go
index b88afb575535..24b880234bf7 100644
--- a/client.go
+++ b/client.go
@@ -163,6 +163,19 @@ func (c *Client) Do(req *Request) (*Response, error) {
// - Blob ID may become invalid after some time if it is unused.
// - Blob ID is usable only by the uploader until it is used, even for shared accounts.
func (c *Client) Upload(accountID ID, blob io.Reader) (*UploadResponse, error) {
	return c.UploadWithContext(context.Background(), accountID, blob)
}

// UploadWithContext sends binary data to the server and returns blob ID and
// some associated meta-data.
//
// There are some caveats to keep in mind:
// - Server may return the same blob ID for multiple uploads of the same blob.
// - Blob ID may become invalid after some time if it is unused.
// - Blob ID is usable only by the uploader until it is used, even for shared accounts.
func (c *Client) UploadWithContext(
	ctx context.Context, accountID ID, blob io.Reader,
) (*UploadResponse, error) {
	c.Lock()
	if c.SessionEndpoint == "" {
		c.Unlock()
@@ -210,6 +223,13 @@ func (c *Client) Upload(accountID ID, blob io.Reader) (*UploadResponse, error) {

// Download downloads binary data by its Blob ID from the server.
func (c *Client) Download(accountID ID, blobID ID) (io.ReadCloser, error) {
	return c.DownloadWithContext(context.Background(), accountID, blobID)
}

// DownloadWithContext downloads binary data by its Blob ID from the server.
func (c *Client) DownloadWithContext(
	ctx context.Context, accountID ID, blobID ID,
) (io.ReadCloser, error) {
	c.Lock()
	if c.SessionEndpoint == "" {
		c.Unlock()
-- 
2.43.0