get-bytevector-n(3scm)
πΈ bestie's guide to get-bytevector-n(3scm) πΈ
okay so welcome to the get-bytevector-n(3scm) page from the Scheme Programmer's Manual π. This is the group-chat rundown for get-bytevector-n and read-bytevector β the βgimme bytes from a binary portβ icons. Let's get into it, no cap β¨π
π NAME π
get-bytevector-n,read-bytevectorβ read data from a binary port
π LIBRARY π
import these bad boys depending on your flavor:
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
(import (scheme base)) ;R7RS
β¨ SYNOPSIS β¨
;; R6RS
(get-bytevector-n binary-input-port k)
;; R7RS
(read-bytevector k)
(read-bytevector k binary-input-port)
π¦ DESCRIPTION π¦
Okay so what it does: it reads from binary-input-port, blocking as necessary, until count bytes are available from binary-input-port or until an end of file is reached. If an end of file is reached before any bytes are available then the end-of-file object is returned. The input port is updated to point just past the bytes read. Literally the byte-reading main character energy π«Άβ¨
R7RS β The default value forbinary-input-portis the object returned bycurrent-input-port(3scm). π
π Multiple end-of-file conditions π
This is the chaotic part, bestie: the port may return an end-of-file object and then still keep producing data if another read is attempted. Files do not normally work this way, but it is possible for other types of ports to do so, such as terminals. R6RS explicitly mentions this situation while R7RS does not. iykyk π
π RETURN VALUES π
Returns a single value; a bytevector or an end-of-file object. An empty bytevector is returned if k is zero. π
- R6RS β There is a single, unique end-of-file object.
π EXAMPLES π
(call-with-port (open-file-input-port "/dev/zero")
(lambda (p)
(get-bytevector-n p 4)))
=> #vu8(0 0 0 0)
Not the /dev/zero serving infinite zeros and the procedure just grabbing exactly 4 bytes ππ
π¨ 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. In particular,countmust be an exact, nonnegative integer object, andbinary-input-portmust be an open binary input port.&i/o-read(R6RS) β There was an I/O error during the read operation.&i/o-port(R6RS) β This condition specifies the port object related to an&i/o-readcondition.- 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. fail catastrophically is sending me π
π SEE ALSO π
eof-object?(3scm), get-bytevector-some(3scm), get-bytevector-all(3scm), get-bytevector-n!(3scm)
π STANDARDS π
R6RS, R7RS
π°οΈ HISTORY π°οΈ
Reports prior to R6RS did not support binary I/O. a little lore for you π
π«Ά AUTHORS π«Ά
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.
π BUGS π
The default port used by read-bytevector is the current input port, which is normally a textual port that is not expected to support binary I/O. so maybe don't expect your text port to suddenly do binary, bestie π
π That's a wrap on the get-bytevector-n(3scm) page β dated 2023-01-30, from the scheme-manpages source. Go read those bytes and slay, icon behavior only β¨π
π¦
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms