Skip to content
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

Improve file reading #296

Merged
merged 9 commits into from
Jan 5, 2022
Merged

Improve file reading #296

merged 9 commits into from
Jan 5, 2022

Conversation

vinc
Copy link
Owner

@vinc vinc commented Jan 1, 2022

  • Rename api::fs::read(path) to api::fs::read_to_bytes(path)
  • Add api::fs::read(path, buf)
  • Move api::fs::canonicalize(path) to kernel internal in sys::fs
  • Add (read-bytes <path> <len>) to read len bytes from a file in lisp
  • Add (bytes <str>) to transform a string into a list of bytes in lisp
  • Add (str <bytes>) to transform a list of bytes into a string in lisp
  • Add progn (aliased to do) to evaluate a sequence of expression in lisp

@vinc
Copy link
Owner Author

vinc commented Jan 1, 2022

> (read-bytes "/tmp/alice.txt" 5)
(65 76 73 67 69)

> (str (read-bytes "/tmp/alice.txt" 5))
"ALICE"

> (first (read-bytes "/dev/random" 1))
145

> (first (read-bytes "/dev/random" 1))
114

> (first (read-bytes "/dev/random" 1))
10

@vinc
Copy link
Owner Author

vinc commented Jan 4, 2022

This example read the console to detect the ANSI escape code ^[A for cursor up:

> (defn read-char () (read-bytes "/dev/console" 4))
read-char

> (eq (do (read-char) (read-char) (read-char)) (bytes "A"))
true

@vinc vinc marked this pull request as ready for review January 5, 2022 18:41
@vinc vinc merged commit e2ff0ac into trunk Jan 5, 2022
@vinc vinc deleted the feature/improve-reading branch January 5, 2022 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant