Skip to content

Commit aeed894

Browse files
up-fs-hex: Update getStorageSize as private variable will always contain a value.
1 parent 696acf6 commit aeed894

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/__tests__/micropython-fs-hex.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,25 @@ describe('Test MicroPython hex filesystem size.', () => {
659659
// Calculated by hand from the uPyHexFile v1.0.1 release.
660660
expect(totalSize).toEqual(27 * 1024);
661661
});
662+
663+
it('Get available fs space when manually set in constructor.', () => {
664+
const micropythonFs = new MicropythonFsHex({ maxFsSize: 1024 });
665+
666+
const totalSize = micropythonFs.getStorageSize();
667+
668+
expect(totalSize).toEqual(1024);
669+
});
670+
671+
it('Get available fs space when both hex and constructor value are provided.', () => {
672+
const micropythonFs = new MicropythonFsHex({
673+
uPyHex: uPyHexFile,
674+
maxFsSize: 1024,
675+
});
676+
677+
const totalSize = micropythonFs.getStorageSize();
678+
679+
expect(totalSize).toEqual(1024);
680+
});
662681
});
663682

664683
/*

src/micropython-fs-hex.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,13 @@ export class MicropythonFsHex implements FsInterface {
202202
}
203203

204204
/**
205-
* Calculate the MicroPython filesystem total size.
206-
* If an max storage size limit has been set, it returns this number.
205+
* The available filesystem total size either calculated by the MicroPython
206+
* hex or the max storage size limit has been set.
207207
*
208208
* @returns Size of the filesystem in bytes.
209209
*/
210210
getStorageSize(): number {
211-
return this._storageSize
212-
? this._storageSize
213-
: getIntelHexFsSize(this._intelHex);
211+
return this._storageSize;
214212
}
215213

216214
/**

0 commit comments

Comments
 (0)