[plt-scheme] resources-fork size under MacOS classic
At Thu, 10 Oct 2002 08:19:29 +0200, "Nicolas Chevallier" wrote:
> Is there anyway to get the logical the data-fork size or the resources-size
> under MacOS classic?
> (file-size path) returns the sum of them.
Here's some code that I use.
; file-path-string -> num
(define (data-fork-size dest)
(if (eq? (system-type) 'macos)
;; Can't use `file-size', because that includes the resource fork.
;; Read all the data to EOF, then check the position of the file
;; pointer. (Maybe using file-position with a big number to
;; move the pointer would be better than reading?)
(let ([p (open-input-file dest)]
[s (make-string 4096)])
(let loop ()
(if (eof-object? (read-string-avail! s p))
(begin0
(file-position p)
(close-input-port p))
(loop))))
;; File has only a "data fork":
(file-size dest)))
Matthew