file-string-length
file-string-length Function
Syntax:
file-string-length stream object → length
Arguments and Values:
stream—an output character file stream.
object—a string or a character .
length—a non-negative integer , or nil.
Description:
file-string-length returns the difference between what (file-position stream) would be after writing object and its current value, or nil if this cannot be determined.
The returned value corresponds to the current state of stream at the time of the call and might not be the same if it is called again when the state of the stream has changed.
openExpanded Reference: file-string-length
Basic Usage
file-string-length returns the number of file-position units that would be consumed by writing a character or string to a character output file stream. Returns NIL if this cannot be determined.
(with-open-file (s "/tmp/cl-fsl-test.txt"
:direction :output :if-exists :supersede)
(file-string-length s #\A))
; Returns a non-negative integer or NIL (implementation-dependent)
With a String Argument
When given a string, returns the total length for writing the entire string.
(with-open-file (s "/tmp/cl-fsl-test.txt"
:direction :output :if-exists :supersede)
(file-string-length s "hello"))
; Returns a non-negative integer or NIL (implementation-dependent)
Relationship to file-position
The value represents the difference file-position would show after writing the object compared to before.
(with-open-file (s "/tmp/cl-fsl-test.txt"
:direction :output :if-exists :supersede)
(let ((before (file-position s)))
(write-string "test" s)
(let ((after (file-position s)))
(when (and before after)
(- after before)))))
=> 4