Sujet : Re: Is there an efficient way to get file length w/o reading file?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 02. Sep 2024, 21:58:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vb55ds$2vl6e$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Bourguignon wrote:
An intelligent implementation could avoid reading the file.
But otherwise, the answer is that it's not possible portably.
Drop down to the POSIX API.
>
How does one do that? Is there an example somewhere?
(defun file-length-in-bytes (file)
;; Note the "EXT" implementation specific package.
(with-open-stream (in (ext:run-program "/bin/ls"
:arguments (list "-l" (namestring file))
:output :stream))
(read in)(read in)(read in)(read in)(read in)))
Alternatively, one could use FFI:
(defun file-length-in-bytes (file)
(multiple-value-bind (res stat) (linux:stat (namestring file))
(linux:|stat-st_size| stat)))
Gauche Scheme:
(use file.util)
(file-size "data.txt")