Skip to content

Commit

Permalink
feat: doc import & doc export commands (#1563)
Browse files Browse the repository at this point in the history
## Description

- adds doc import / doc export commands on the cli
- `doc import` can import a file or directory
- `doc export` exports a single entry as a file
- adds `DocClient::doc_set_hash` that sets an entry in a document by
using the hash, key, and size of the entry.

 
## Notes & open questions

Re-implementation of #1504, but
it has drifted so far that it is now easier to start a new PR.

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [x] Tests if relevant.

---------

Co-authored-by: Friedel Ziegelmayer <me@dignifiedquire.com>
  • Loading branch information
ramfox and dignifiedquire authored Oct 11, 2023
1 parent af06677 commit 3c0195c
Show file tree
Hide file tree
Showing 6 changed files with 529 additions and 13 deletions.
30 changes: 25 additions & 5 deletions iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ use crate::rpc_protocol::{
BlobListRequest, BlobListResponse, BlobReadRequest, BlobReadResponse, BlobValidateRequest,
CounterStats, DeleteTagRequest, DocCreateRequest, DocDelRequest, DocDelResponse,
DocDropRequest, DocGetManyRequest, DocGetOneRequest, DocImportRequest, DocInfoRequest,
DocLeaveRequest, DocListRequest, DocSetRequest, DocShareRequest, DocStartSyncRequest,
DocSubscribeRequest, DocTicket, GetProgress, ListTagsRequest, ListTagsResponse,
NodeConnectionInfoRequest, NodeConnectionInfoResponse, NodeConnectionsRequest,
NodeShutdownRequest, NodeStatsRequest, NodeStatusRequest, NodeStatusResponse, ProviderService,
ShareMode, WrapOption,
DocLeaveRequest, DocListRequest, DocSetHashRequest, DocSetRequest, DocShareRequest,
DocStartSyncRequest, DocSubscribeRequest, DocTicket, GetProgress, ListTagsRequest,
ListTagsResponse, NodeConnectionInfoRequest, NodeConnectionInfoResponse,
NodeConnectionsRequest, NodeShutdownRequest, NodeStatsRequest, NodeStatusRequest,
NodeStatusResponse, ProviderService, ShareMode, WrapOption,
};
use crate::sync_engine::{LiveEvent, LiveStatus};

Expand Down Expand Up @@ -556,6 +556,26 @@ where
Ok(res.entry.content_hash())
}

/// Set an entries on the doc via its key, hash, and size.
pub async fn set_hash(
&self,
author_id: AuthorId,
key: Vec<u8>,
hash: Hash,
size: u64,
) -> Result<()> {
self.rpc
.rpc(DocSetHashRequest {
doc_id: self.id,
author_id,
key,
hash,
size,
})
.await??;
Ok(())
}

/// Read the content of an [`Entry`] as a streaming [`BlobReader`].
pub async fn read(&self, entry: &Entry) -> Result<BlobReader> {
BlobReader::from_rpc(&self.rpc, entry.content_hash()).await
Expand Down
Loading

0 comments on commit 3c0195c

Please sign in to comment.