@@ -210,6 +210,7 @@ class MicroPythonBoard {
210210 command += ` print(1)\n`
211211 command += `except OSError:\n`
212212 command += ` print(0)\n`
213+ command += `del f\n`
213214 await this . enter_raw_repl ( )
214215 let output = await this . exec_raw ( command )
215216 await this . exit_raw_repl ( )
@@ -240,11 +241,13 @@ class MicroPythonBoard {
240241 let command = `import uos\n`
241242 command += `try:\n`
242243 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`
245246 command += ` print(l)\n`
246247 command += `except OSError:\n`
247248 command += ` print([])\n`
249+ command += `del l\n`
250+ command += `del f\n`
248251 await this . enter_raw_repl ( )
249252 let output = await this . exec_raw ( command )
250253 await this . exit_raw_repl ( )
@@ -259,9 +262,16 @@ class MicroPythonBoard {
259262 async fs_cat_binary ( filePath ) {
260263 if ( filePath ) {
261264 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+
265275 await this . exit_raw_repl ( )
266276 output = extractBytes ( output , 2 , 4 )
267277 return Promise . resolve ( ( output ) )
@@ -273,7 +283,7 @@ class MicroPythonBoard {
273283 if ( filePath ) {
274284 await this . enter_raw_repl ( )
275285 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 `
277287 )
278288 await this . exit_raw_repl ( )
279289 output = extract ( output )
@@ -297,7 +307,7 @@ class MicroPythonBoard {
297307 out += await this . exec_raw ( line )
298308 data_consumer ( parseInt ( ( i / contentBuffer . length ) * 100 ) + '%' )
299309 }
300- out += await this . exec_raw ( `f.close()` )
310+ out += await this . exec_raw ( `f.close()\ndel f\ndel w\n ` )
301311 out += await this . exit_raw_repl ( )
302312 return Promise . resolve ( out )
303313 }
@@ -318,7 +328,7 @@ class MicroPythonBoard {
318328 out += await this . exec_raw ( line )
319329 data_consumer ( parseInt ( ( i / contentBuffer . length ) * 100 ) + '%' )
320330 }
321- out += await this . exec_raw ( `f.close()` )
331+ out += await this . exec_raw ( `f.close()\ndel f\ndel w\n ` )
322332 out += await this . exit_raw_repl ( )
323333 return Promise . resolve ( out )
324334 } else {
0 commit comments