get-bytevector-all(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

✨ get-bytevector-all β€” read bytes until the next end of file ✨

okay so this is get-bytevector-all(3scm), from the Scheme Programmer's Manual (3scm section, bestie πŸ’…). it lives in the scheme-manpages universe and honestly? it's giving "one job, does it perfectly." let's get into it 🫢


🌸 LIBRARY 🌸

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS

two ways to import, same energy. pick your fave, they both slay πŸ’–


✨ SYNOPSIS ✨

(get-bytevector-all binary-input-port)

one argument. one port. no drama. 🌈


πŸ’œ DESCRIPTION πŸ’œ

so what does it do? it reads all the bytes until the next end of file. that's it. that's the whole vibe. and yes, it blocks as necessary β€” it'll sit there and wait like a loyal bestie 🫢

here's the tea, three scenarios:

  • if one or more bytes get read β†’ you get back a bytevector containing all the bytes up to the next end of file, and binary-input-port gets updated to point just past those bytes πŸ‘‘
  • if no bytes get read β†’ you get the end-of-file object back. nothing. nada. the void. πŸ’€
⚠️ heads up bestie: this operation may block indefinitely waiting to see if more bytes will become available β€” even if some bytes are already available. so like, it's committed to the bit. no cap. 😭

πŸŽ€ RETURN VALUES πŸŽ€

returns a single value, which is either a bytevector or the end-of-file object. that's the whole menu. πŸ“


πŸ¦‹ EXAMPLES πŸ¦‹

(call-with-port (open-file-input-port "/etc/machine-id")
  get-bytevector-all)

slurp an entire file in one clean line. iconic. no loop, no mess, just vibes ✨


🌟 APPLICATION USAGE 🌟

this procedure is a convenience β€” it replaces a loop that is, and I quote, "fiddly to make efficient and correct." so basically someone already did the hard part for you, and you get to be lazy about it. we love that for us πŸ’…


πŸ’€ COMPATIBILITY πŸ’€

this procedure is unique to R6RS. so like… it's not everywhere. check before you assume, iykyk πŸ™ˆ


πŸ”₯ ERRORS πŸ”₯

this procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. classic. 😭
  • R7RS β€” the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophically. that's the real word. no cap πŸ’€πŸ”₯

πŸ‘‘ SEE ALSO πŸ‘‘

(yes there's a trailing comma in the original list, we're keeping it, character for character, that's just how it is πŸŽ€)


🧚 STANDARDS 🧚

R6RS β€” that's the whole standard section. short and sweet. ⭐


🌈 HISTORY 🌈

this procedure first appeared in the reworked I/O system in R6RS. so it's a glow-up baby. main character energy from day one πŸ‘‘


πŸ’– AUTHORS πŸ’–

this page is part of the scheme-manpages project. it includes materials from the RnRS documents. more info can be found at https://github.com/schemedoc/manpages/. 🫢


and that's the whole page, bestie!! 🌸 written by the scheme-manpages girlies, dated 2023-02-01, served fresh from the Scheme Programmer's Manual, get-bytevector-all(3scm). mwah πŸ’‹βœ¨
πŸ“¦ where this page comes from