Skip to content

[MOO-2482]: File System APIs for getFileSize and writeChunk - #66

Open
MxKevinBeqo wants to merge 6 commits into
mainfrom
moo/MOO-2482-resumable-download-apis
Open

MxKevinBeqo wants to merge 6 commits into
mainfrom
moo/MOO-2482-resumable-download-apis

Conversation

@MxKevinBeqo

Copy link
Copy Markdown
Contributor

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).

@MxKevinBeqo MxKevinBeqo self-assigned this Sep 15, 2026
@MxKevinBeqo MxKevinBeqo added the enhancement New feature or request label Sep 15, 2026
@YogendraShelke

Copy link
Copy Markdown
Collaborator

Rebasing should fix the Android build issue.

@MxKevinBeqo
MxKevinBeqo force-pushed the moo/MOO-2482-resumable-download-apis branch from 2a6f536 to 79aa922 Compare September 28, 2026 11:38

fun getFileSize(filePath: String): Long {
val file = File(filePath)
return if (file.exists()) file.length() else 0L

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback makes differentiation difficult. A file doesn’t exist and a file with zero size are indistinguishable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an exception when a file does not exist would make more sense, of course, if the offline team is okay with that.

Comment thread src/file-system/index.ts
//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) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe exposing dedicated functions like saveBlob and saveBase would improve readability and maintainability.

Comment thread src/file-system/index.ts

//Methods - file operations required for resumable downloads
getFileSize: NativeMxFileSystem.getFileSize,
writeChunk: (data: BlobData | string, filePath: string, offset: number) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, having dedicated functions for blob and base64.


let fileManager = FileManager.default
guard fileManager.fileExists(atPath: filePath) else {
resolve(NSNumber(value: 0))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, too, throw an exception if size determination fails instead of falling back to the default 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants