Skip to content

Development to main #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions micropython.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function extract(out) {
return out.slice(2, -3)
}

function extractBytes(out, cut_before = 2, cut_after = 3) {
bytes = out.slice(cut_before, -cut_after)
bytes = bytes.split(',').map(Number)
return bytes
}

class MicroPythonBoard {
constructor() {
this.port = null
Expand Down Expand Up @@ -250,6 +256,19 @@ class MicroPythonBoard {
return Promise.resolve(files)
}

async fs_cat_binary(filePath) {
if (filePath) {
await this.enter_raw_repl()
let output = await this.exec_raw(
`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=',')`
)
await this.exit_raw_repl()
output = extractBytes(output, 2, 4)
return Promise.resolve((output))
}
return Promise.reject(new Error(`Path to file was not specified`))
}

async fs_cat(filePath) {
if (filePath) {
await this.enter_raw_repl()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micropython.js",
"version": "1.4.4",
"version": "1.5.0",
"description": "Interpretation of pyboard.py in javascript",
"main": "micropython.js",
"scripts": {
Expand Down