Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: How much does it cost to ride the Unibus? A: 2 bits.


comp / comp.lang.lisp / Re: Is there an efficient way to get file length w/o reading file?

SubjectAuthor
o Re: Is there an efficient way to get file length w/o reading file?B. Pym

1
Subject: Re: Is there an efficient way to get file length w/o reading file?
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 2 Sep 2024 19:58 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Is there an efficient way to get file length w/o reading file?
Date: Mon, 2 Sep 2024 19:58:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <vb55ds$2vl6e$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 02 Sep 2024 21:58:57 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a435632fcbba468531e98d5e4c12abf8";
logging-data="3134670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FYpz2SAYHWHcoqTH5AROg"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:qd2eN3lI3k5ydkDZJHNbptHtMww=
View all headers

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")

1

rocksolid light 0.9.8
clearnet tor