diff --git a/README.md b/README.md index 9a95f8b..875ea19 100644 --- a/README.md +++ b/README.md @@ -54,29 +54,34 @@ 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) // +//************************************************************************************************// -/* - 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 -/* +/* 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 -*/ +//************************************************************************************************// +// Step 2. Create an 'api' instance using the connection pool / connection // +//************************************************************************************************// + const api = rep.create_api(conn); -/* - Step 3. Use 'api' -*/ +//************************************************************************************************// +// 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++) { @@ -91,14 +96,18 @@ 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 +// Download a remote file and overwrite existing local file await api.file.download('/my_file.txt', 'C:\\my_file.txt', progress_cb, true); // Resume failed download @@ -106,4 +115,52 @@ await api.file.download('/my_file.txt', 'C:\\my_file.txt', progress_cb, false, t // Upload a local file await api.file.upload('C:\\my_file.txt', '/my_file.txt', progress_cb); + +// Upload a local file and overwrite existing remote file +await api.file.upload('C:\\my_file.txt', '/my_file.txt', progress_cb, true); + +// Resume failed upload +await api.file.upload('C:\\my_file.txt', '/my_file.txt', progress_cb, false, true); + + +//------------------------------------------------------------------------------------------------// +// *********** Low-Level File Operations *********** // +//------------------------------------------------------------------------------------------------// + +// Create or open a remote file +{ + const f = await api.file.create_or_open('/my_file.txt'); + await f.close(); +} + +// Open an existing remote file +{ + const f = await api.file.open('/my_file.txt'); + await f.close(); +} + +// Write to a file +{ + const f = await api.file.create_or_open('/my_file.txt'); + + const b = Buffer.alloc(1); + b[0] = 1; + await f.write(0, b); // write '1' byte at file offset '0' + + await f.close(); +} + +// Read from a file +{ + const f = await api.file.create_or_open('/my_file.txt'); + const b = await f.read(0, 1); // read '1' byte from file offset '0' + await f.close(); +} + +// Truncate / resize file +{ + const f = await api.file.create_or_open('/my_file.txt'); + const b = await f.truncate(10); + await f.close(); +} ```