Repository navigation
[MOO-2482]: File System APIs for getFileSize and writeChunk - #66
MxKevinBeqo wants to merge 9 commits into
Conversation
|
Rebasing should fix the Android build issue. |
2a6f536 to
79aa922
Compare
|
|
||
| fun getFileSize(filePath: String): Long { | ||
| val file = File(filePath) | ||
| return if (file.exists()) file.length() else 0L |
There was a problem hiding this comment.
This fallback makes differentiation difficult. A file doesn’t exist and a file with zero size are indistinguishable.
There was a problem hiding this comment.
Throwing an exception when a file does not exist would make more sense, of course, if the offline team is okay with that.
| //Methods - signature modified since specs does not recognize Record<string, any> and generics | ||
| save: (blob: BlobData, filePath: string) => | ||
| NativeMxFileSystem.save(blob, filePath), | ||
| save: (data: BlobData | string, filePath: string) => |
There was a problem hiding this comment.
I believe exposing dedicated functions like saveBlob and saveBase would improve readability and maintainability.
|
|
||
| //Methods - file operations required for resumable downloads | ||
| getFileSize: NativeMxFileSystem.getFileSize, | ||
| writeChunk: (data: BlobData | string, filePath: string, offset: number) => |
There was a problem hiding this comment.
Same as above, having dedicated functions for blob and base64.
|
|
||
| let fileManager = FileManager.default | ||
| guard fileManager.fileExists(atPath: filePath) else { | ||
| resolve(NSNumber(value: 0)) |
There was a problem hiding this comment.
Same as above, returning an exception when the file does not exist.
|
|
||
| do { | ||
| let attributes = try fileManager.attributesOfItem(atPath: filePath) | ||
| let size = attributes[.size] as? UInt64 ?? 0 |
There was a problem hiding this comment.
Here, too, throw an exception if size determination fails instead of falling back to the default 0.
Previously getFileSize resolved 0 for a non-existent file and when the size attribute could not be read, making a missing file indistinguishable from an empty one. It now rejects with ERROR_READ_FAILED on both platforms. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Instead of overloading save and writeChunk to accept BlobData | string, add saveBase64 and writeChunkBase64 to NativeFileSystem. save and writeChunk accept a blob only again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
With encryption enabled, saveBase64 goes through the regular save path and the stored file is larger than the payload on Android, so asserting on getFileSize failed. Read the file back with readAsDataURL instead.
This PR adds 2 new file system APIs to to get the size of a file and the perform chunked writing via offset (required for 'pause-resume'-capable functionalities).