Repository navigation
[MOO-2482]: File System APIs for getFileSize and writeChunk - #66
MxKevinBeqo wants to merge 6 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.
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).