Skip to content

Commit d0b6f4c

Browse files
upy-fs-hex: Move common import hex method arguments into ImportOptions interface.
1 parent adebf8b commit d0b6f4c

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/micropython-fs-hex.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {
1818
import { SimpleFile } from './simple-file';
1919
import { areUint8ArraysEqual } from './common';
2020

21+
/**
22+
* Extends the interface from microbit-fs-building to include the board ID that
23+
* corresponds to each of the cached objects.
24+
*/
2125
interface MpFsBuilderCacheWithId extends MpFsBuilderCache {
2226
boardId: number;
2327
}
@@ -32,6 +36,14 @@ export interface IntelHexWithId {
3236
boardId: number;
3337
}
3438

39+
/**
40+
* Options for importing Hex files into a MicropythonFsHex instance.
41+
*/
42+
export interface ImportOptions {
43+
overwrite?: boolean;
44+
formatFirst?: boolean;
45+
}
46+
3547
/**
3648
* Manage filesystem files in one or multiple MicroPython hex files.
3749
*
@@ -301,10 +313,7 @@ export class MicropythonFsHex implements FsInterface {
301313
*/
302314
importFilesFromIntelHex(
303315
intelHex: string,
304-
{
305-
overwrite = false,
306-
formatFirst = false,
307-
}: { overwrite?: boolean; formatFirst?: boolean } = {}
316+
{ overwrite = false, formatFirst = false }: ImportOptions = {}
308317
): string[] {
309318
const files = getIntelHexFiles(intelHex);
310319
if (!Object.keys(files).length) {
@@ -347,10 +356,7 @@ export class MicropythonFsHex implements FsInterface {
347356
*/
348357
importFilesFromUniversalHex(
349358
universalHex: string,
350-
{
351-
overwrite = false,
352-
formatFirst = false,
353-
}: { overwrite?: boolean; formatFirst?: boolean } = {}
359+
{ overwrite = false, formatFirst = false }: ImportOptions = {}
354360
): string[] {
355361
if (!microbitUh.isUniversalHex(universalHex)) {
356362
throw new Error('Universal Hex provided is invalid.');
@@ -428,17 +434,7 @@ export class MicropythonFsHex implements FsInterface {
428434
* erases the files after there are no error during hex file parsing.
429435
* @returns A filename list of added files.
430436
*/
431-
importFilesFromHex(
432-
hexStr: string,
433-
{
434-
overwrite = false,
435-
formatFirst = false,
436-
}: { overwrite?: boolean; formatFirst?: boolean } = {}
437-
) {
438-
const options = {
439-
overwrite,
440-
formatFirst,
441-
};
437+
importFilesFromHex(hexStr: string, options: ImportOptions = {}) {
442438
return microbitUh.isUniversalHex(hexStr)
443439
? this.importFilesFromUniversalHex(hexStr, options)
444440
: this.importFilesFromIntelHex(hexStr, options);

0 commit comments

Comments
 (0)