Load the export directory size
Node · Node · intermediate · greenfield
Adds a small helper around fs.stat to read a file's size before we stream it. Awaits the stat call and returns the size in bytes.
Runs inside the export service on Node 20; the project has no custom fs wrappers.
Requirements
- Add a helper that returns the size (in bytes) of a file in the exports directory.
- Use the fs module's stat call.
- Return the size as a number; let errors propagate to the caller.
Files touched
- src/exports/fileSize.js
--- src/exports/fileSize.js
+const fs = require('fs');
+
+async function fileSize(path) {
+ const stats = await fs.stat(path);
+ return stats.size;
+}
+
+module.exports = { fileSize };