sunterlib/scsh/dir-streams/README

163 lines
4.3 KiB
Plaintext
Raw Normal View History

2003-02-22 03:19:10 -05:00
The structure DIR-STREAMS defines procedures to represent and process
directories as streams of files and sub-directories. Using a lazy data
structure to represent directories allows the library to minimize
access to the file system. Files within streams are represented by the
data type FS-OBJECT which essentially extends scsh's FILE-INFO type by
a field for the file name.
In addition the structure STREAM provides a library for stream
processing but we intend to replace this library with SRFI-40
soon. This is also the reason for the lack of documentation for the
STREAM package.
2003-02-17 07:13:55 -05:00
2003-02-20 17:46:41 -05:00
(dir-stream-from-dir-name dir-name [chase?] [parent]) -> dir-stream
2003-02-17 07:13:55 -05:00
2003-02-22 03:19:10 -05:00
Constructor for dir-streams. The CHASE? option indicates whether
symbolic links should be followed or not and defaults to #t. PARENT is
the directory relative to which DIR-NAME should be interpreted. It
defaults to "" and is only mildly useful.
2003-02-17 07:13:55 -05:00
(dir-stream? thing) -> boolean
2003-02-20 17:46:41 -05:00
2003-02-17 07:13:55 -05:00
Type predicate for dir-streams.
(dir-stream-info dir-stream) -> fs-object
Returns the fs-object corresponding to the directory.
2003-02-20 17:46:41 -05:00
2003-02-17 07:13:55 -05:00
(fs-object? thing) -> boolean
Type predicate for file-objects.
2003-02-20 17:46:41 -05:00
2003-02-17 07:13:55 -05:00
(fs-object-parent fs-object) -> string
The parent directory of the fs-object.
(fs-object-name fs-object) -> string
2003-02-22 03:19:10 -05:00
The file name of FS-OBJECT.
2003-02-17 07:13:55 -05:00
(fs-object-info fs-object) -> file-info
2003-02-22 03:19:10 -05:00
The file-info record of FS-OBJECT.
2003-02-17 07:13:55 -05:00
(fs-object-file-name fs-object) -> string
2003-02-22 03:19:10 -05:00
The path of FS-OBJECT.
2003-02-17 07:13:55 -05:00
(dir-stream-files-stream dir-steam) -> fs-object stream
2003-02-22 03:19:10 -05:00
A stream of the fs-objects of the files within the directory
represented by DIR-STREAM.
2003-02-17 07:13:55 -05:00
(dir-stream-subdir-stream dir-stream) -> dir-stream stream
2003-02-22 03:19:10 -05:00
A stream of dir-streams of the subdirectories within the directory
represented by DIR-STREAM.
2003-02-17 07:13:55 -05:00
(dir-stream-filter dir-stream file-pred dir-pred) -> dir-stream
Applies the predicate DIR-PRED to all the subdirectories and FILE-PRED
to all the files within directory. The returned stream contains only
the files and subdirectories for which the predicates return #t.
(dir-stream-fold-right ds make-dir-stream
files-make-stream files-stream-empty
subdirs-make-stream subdirs-empty) -> return type of make-dir-stream
2003-02-20 17:46:41 -05:00
Replaces the constructors of the dir-stream by the supplied procedures.
2003-02-17 07:13:55 -05:00
Example:
(define (disc-usage ds)
(dir-stream-fold-right ds (lambda (fso sum subdirs) (list (fs-object-filename fso)
(apply + sum (map cadr subdirs))
subdirs))
(lambda (fso accu)
(+ accu (file-info:size (fs-object-info fso))))
0
cons
'()))
2003-02-22 03:19:10 -05:00
(dir-stream-map dir-stream file-f dir-f) -> dir-stream
Applies FILE-F to all files in DIR-STREAM and DIR-F to all directories
in DIR-STREAM and returns the resulting dir-stream.
(dir-stream-filter-map dir-stream file-f dir-f) -> dir-stream
2003-02-17 07:13:55 -05:00
2003-02-22 03:19:10 -05:00
Applies FILE-F to all files in DIR-STREAM and DIR-F to all directories
in DIR-STREAM and returns the dir-stream containing all the non-false
results of FILE-F and DIR-F.
2003-02-17 07:13:55 -05:00
2003-02-22 03:19:10 -05:00
(dir-stream-for-each dir-stream file-f dir-f) -> unspecific
2003-02-17 07:13:55 -05:00
2003-02-22 03:19:10 -05:00
Applies FILE-F to all files in DIR-STREAM and DIR-F to all directories
in DIR-STREAM.
2003-02-17 07:13:55 -05:00
2003-02-22 03:19:10 -05:00
The structure DIR-STREAM-PREDICATES defines some predicates the user
might find useful when programming with dir-streams.
(fs-object-size-less-than? fs-object size) -> {#t, #f}
(fs-object-size-greater-than? fs-object size) -> {#t, #f}
2003-02-22 03:19:10 -05:00
Check whether the lenght of the file represented by FS-OBJECT is
less/more than SIZE bytes.
(days->seconds days) -> integer
(hours->seconds hours) -> integer
(minutes->seconds minutes) -> integer
Auxiliary functions for converting an integer representing a count of
days/hours/minutes to an integer representing that amount of time in
seconds.
2003-02-22 03:19:10 -05:00
(fs-object-last-modified-in? fs-object pair) -> {#t, #f}
(fs-object-last-accessed-in? fs-object pair) -> {#t, #f}
(fs-object-created-in? fs-object pair) -> {#t, #f}
2003-02-22 03:19:10 -05:00
PAIR is a pair representing an interval of time. These functions check
whether the date when then file represented by FS-OBJECT was last
modified/last-accessed/created lies in this interval (includes left
and right boundary of the interval).
2003-02-22 03:19:10 -05:00
(fs-object-name-matches? fs-object regexp) -> {#t, #f}
2003-02-22 03:19:10 -05:00
Returns #t if REGEXP-SEARCH? for regexp matches the filename of the
file represented by FS-OBJECT.
2003-02-22 03:19:10 -05:00
(ds-object-file-name-matches? fs-object regexp) -> {#t, #f}
Returns #t if REGEXP-SEARCH? for regexp matches the filename
(including the absolute path) of the file represented by FS-OBJECT.