Hello,
I'm encountering an issue when attempting to save a large file (150 MB) downloaded from the internet to disk using the fs plugin with writeFile. Here's a simplified version of the code I'm using:
async function downloadAndSaveFile(url, fileName) {
try {
const response = await fetch(url, { method: 'GET' });
if (!response.ok) {
throw new Error(`Error downloading file: ${response.statusText}`);
}
const fileData = new Uint8Array(await response.arrayBuffer());
const contentLength = response.headers.get('content-length');
console.log(`File size: ${contentLength} bytes, actual downloaded data size: ${fileData.byteLength} bytes`);
// Write the entire file to disk in a single operation
await writeFile(fileName, fileData, {
baseDir: BaseDirectory.AppCache,
create: true
});
console.log(`File ${fileName} successfully saved in cache directory.`);
} catch (error) {
console.error(`Error downloading or saving file: ${error}`);
}
}
The code works perfectly for smaller files (tested with files around 11 MB), confirming that the necessary write permissions for the plugin are in place. Additionally, the device has sufficient storage and memory. However, when trying to save a larger file (150 MB), the app crashes during the write operation.
Could this be an issue with memory allocation when handling larger files, or is there an additional configuration or limitation with the fs plugin when processing large files? Any advice or suggestions would be greatly appreciated.
Thank you!