support base64 writes

This commit is contained in:
2021-06-05 23:12:32 -05:00
parent 95075539d5
commit 806363a1c9
3 changed files with 54 additions and 0 deletions

View File

@@ -1,5 +1,8 @@
# Changelog # Changelog
## 1.3.1-r4
- Support writing base64 string data
## 1.3.1-r3 ## 1.3.1-r3
- Added directory/file exists - Added directory/file exists
- Fix unit tests - Fix unit tests

View File

@@ -89,4 +89,20 @@ export default class file {
this.thread_id this.thread_id
); );
} }
async write_base64(offset, base64_string) {
if (this.handle === null) {
return Promise.reject(
new Error("'write_base64()' failed: invalid handle")
);
}
return ops.write_base64_file(
this.conn,
this.handle,
this.remote_path,
offset,
base64_string,
this.thread_id
);
}
} }

View File

@@ -577,6 +577,41 @@ export const upload_file = async (
} }
}; };
export const write_base64_file = async (
conn,
handle,
remote_path,
offset,
base64_string,
optional_thread_id
) => {
try {
const buffer = new Uint8Array(new TextEncoder().encode(base64_string));
const request = new packet();
request.encode_utf8(remote_path);
request.encode_ui64(buffer.length);
request.encode_buffer(buffer);
request.encode_ui64(offset);
request.encode_ui64(handle);
const response = await conn.send(
'::RemoteFUSEWriteBase64',
request,
optional_thread_id
);
response.decode_ui32(); // Service flags
const result = response.decode_i32();
if (result === buffer.length) {
return result;
}
return Promise.reject(new Error(`'write_base64_file' error: ${result}`));
} catch (err) {
return Promise.reject(new Error(`'write_base64_file' failed: ${err}`));
}
};
export const write_file = async ( export const write_file = async (
conn, conn,
handle, handle,