@@ -210,6 +210,7 @@ class MicroPythonBoard {
210
210
command += ` print(1)\n`
211
211
command += `except OSError:\n`
212
212
command += ` print(0)\n`
213
+ command += `del f\n`
213
214
await this . enter_raw_repl ( )
214
215
let output = await this . exec_raw ( command )
215
216
await this . exit_raw_repl ( )
@@ -240,11 +241,13 @@ class MicroPythonBoard {
240
241
let command = `import uos\n`
241
242
command += `try:\n`
242
243
command += ` l=[]\n`
243
- command += ` for file in uos.ilistdir("${ folderPath } "):\n`
244
- command += ` l.append(list(file ))\n`
244
+ command += ` for f in uos.ilistdir("${ folderPath } "):\n`
245
+ command += ` l.append(list(f ))\n`
245
246
command += ` print(l)\n`
246
247
command += `except OSError:\n`
247
248
command += ` print([])\n`
249
+ command += `del l\n`
250
+ command += `del f\n`
248
251
await this . enter_raw_repl ( )
249
252
let output = await this . exec_raw ( command )
250
253
await this . exit_raw_repl ( )
@@ -259,9 +262,16 @@ class MicroPythonBoard {
259
262
async fs_cat_binary ( filePath ) {
260
263
if ( filePath ) {
261
264
await this . enter_raw_repl ( )
262
- let output = await this . exec_raw (
263
- `with open('${ filePath } ','rb') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(",".join(str(e) for e in b),end=',')`
264
- )
265
+ const chunkSize = 256
266
+ let command = `with open('${ filePath } ','rb') as f:\n`
267
+ command += ` while 1:\n`
268
+ command += ` b=f.read(${ chunkSize } )\n`
269
+ command += ` if not b:break\n`
270
+ command += ` print(",".join(str(e) for e in b),end=',')\n`
271
+ command += `del f\n`
272
+ command += `del b\n`
273
+ let output = await this . exec_raw ( command )
274
+
265
275
await this . exit_raw_repl ( )
266
276
output = extractBytes ( output , 2 , 4 )
267
277
return Promise . resolve ( ( output ) )
@@ -273,7 +283,7 @@ class MicroPythonBoard {
273
283
if ( filePath ) {
274
284
await this . enter_raw_repl ( )
275
285
let output = await this . exec_raw (
276
- `with open('${ filePath } ','r') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(b,end='')`
286
+ `with open('${ filePath } ','r') as f:\n while 1:\n b=f.read(256)\n if not b:break\n print(b,end='')\ndel f\ndel b\n `
277
287
)
278
288
await this . exit_raw_repl ( )
279
289
output = extract ( output )
@@ -297,7 +307,7 @@ class MicroPythonBoard {
297
307
out += await this . exec_raw ( line )
298
308
data_consumer ( parseInt ( ( i / contentBuffer . length ) * 100 ) + '%' )
299
309
}
300
- out += await this . exec_raw ( `f.close()` )
310
+ out += await this . exec_raw ( `f.close()\ndel f\ndel w\n ` )
301
311
out += await this . exit_raw_repl ( )
302
312
return Promise . resolve ( out )
303
313
}
@@ -318,7 +328,7 @@ class MicroPythonBoard {
318
328
out += await this . exec_raw ( line )
319
329
data_consumer ( parseInt ( ( i / contentBuffer . length ) * 100 ) + '%' )
320
330
}
321
- out += await this . exec_raw ( `f.close()` )
331
+ out += await this . exec_raw ( `f.close()\ndel f\ndel w\n ` )
322
332
out += await this . exit_raw_repl ( )
323
333
return Promise . resolve ( out )
324
334
} else {
0 commit comments