From 2fcc38fe3c78e0d33276c69b0a78082605b2162a Mon Sep 17 00:00:00 2001 From: Scott Graves Date: Wed, 3 Mar 2021 17:12:02 +0000 Subject: [PATCH] README.md added --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8bdd7a9 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# About +`repertory-js` is a client library used to communicate with `repertory's` remote API. + +## Example Usage +``` javascript +const rep = require('@scottg1/repertory-js'); + + +// Repertory host settings +const MY_HOST_OR_IP = 'localhost'; +const MY_PORT = 20000; +const MY_TOKEN = 'password'; + +// Progress callback for uploads / downloads +const progress_cb = (local_path, remote_path, progress, completed) => { + console.log(local_path, remote_path, progress, completed); +} + +/* + Step 1. Create a connection pool (recommended) +*/ +const conn = await rep.create_pool(8, MY_HOST_OR_IP, MY_PORT, MY_TOKEN); + +// Or create a single connection for light operations +/* + const conn = await rep.connect(MY_HOST_OR_IP, MY_PORT, MY_TOKEN); +*/ + + +/* + Step 2. Create an 'api' instance using the connection pool / connection +*/ +const api = rep.create_api(conn); + + +/* + Step 3. Use 'api' +*/ +// *********** Directory Operations *********** // +// List directory contents +await api.directory.list('/', async (remote_path, page_count, get_page) => { + for (let i = 0; i < page_count; i++) { + const items = await get_page(i); // Always 'await' + console.log(items); + } +}); + +// Create new directory +await api.directory.create('/test'); + +// Remove existing directory +await api.directory.remove('/test') + +// *********** File Operations *********** // +// Delete a file +await api.file.delete('/my_file.txt') + +// Download a remote file +await api.file.download('/my_file.txt', 'C:\\my_file.txt', progress_cb); + +// Download a remote file and overwrite existing local file if it exists +await api.file.download('/my_file.txt', 'C:\\my_file.txt', progress_cb, true); + +// Resume failed download +await api.file.download('/my_file.txt', 'C:\\my_file.txt', progress_cb, false, true); + +// Upload a local file +await api.file.upload('C:\\my_file.txt', '/my_file.txt', progress_cb); +``` \ No newline at end of file