8000 Merge pull request #20 from arduino/fix/del-leftover-symbols · arduino/micropython.js@ea101e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea101e5

Browse files
authored
Merge pull request #20 from arduino/fix/del-leftover-symbols
Fix/del leftover symbols - v 1.5.1
2 parents e6bc9bc + 050d300 commit ea101e5

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

micropython.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "micropython.js",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Interpretation of pyboard.py in javascript",
55
"main": "micropython.js",
66
"scripts": {

0 commit comments

Comments
 (0)
0