planck.io

Planck I/O functionality.

Protocols

Coercions
IOFactory

Types

File

Vars

as-file
as-relative-path
as-url
copy
delete-file
directory?
exists?
file
file?
file-attributes
file-name
hidden-file?
input-stream
list-files
make-input-stream
make-output-stream
make-parents
make-reader
make-writer
output-stream
path-elements
reader
regular-file?
resource
symbolic-link?
writer

Protocols

Coercions

Protocol

Coerce between various 'resource-namish' things.

as-file
([x])
Coerce argument to a File.

as-url
([x])
Coerce argument to a goog.Uri.

IOFactory

Protocol

Factory functions that create ready-to-use versions of the various stream types, on top of anything that can be unequivocally converted to the requested kind of stream.

Common options include

:append true to open stream in append mode
:encoding string name of encoding to use, e.g. "UTF-8".

Callers should generally prefer the higher level API provided by reader, writer, input-stream, and output-stream.

make-reader
([x opts])
Creates an IReader. See also IOFactory docs.

make-writer
([x opts])
Creates an IWriter. See also IOFactory docs.

make-input-stream
([x opts])
Creates an IInputStream. See also IOFactory docs.

make-output-stream
([x opts])
Creates an IOutputStream. See also IOFactory docs.

Types

File

Type

Fields: [path]

Represents a file.

Vars

as-file

([x])

Coerce argument to a File.

as-relative-path

([x])

Take an as-file-able thing and return a string if it is a relative path, else throws an exception.

as-url

([x])

Coerce argument to a goog.Uri.

copy

([input output & opts])

Copies input to output. Returns nil or throws an exception.

Input may be an IInputStream or IReader created using planck.io, File, or string.

Output may be an IOutputStram or IWriter created using planck.io, or File.

The opts arg is included for compatibility with clojure.java.io/copy but ignored. If translating between char and byte representations, UTF-8 encoding is assumed.

Does not close any streams except those it opens itself (on a File).

Spec
args: (cat :input any? :output any? :opts (* any?))
ret: nil?

delete-file

([f])

Delete file f.

Spec
args: (cat :f (or :string string? :file file?))

directory?

([dir])

Checks if dir is a directory.

Spec
args: (cat :dir (or :string string? :file file?))
ret: boolean?

exists?

([f])

Checks if f exists on disk.

Spec
args: (cat :f (or :string string? :file file?))
ret: boolean?

file

([arg] [parent child] [parent child & more])

Returns a File, passing each arg to as-file. Multiple-arg versions treat the first argument as parent and subsequent args as children relative to the parent.

Spec
args: (cat :path-or-parent any? :more (* any?))
ret: file?

file?

([x])

Returns true if x is a File.

Spec
args: (s/cat :x any?)
ret: boolean?

file-attributes

([path])

Returns a map containing the attributes of the item at a given path.

Spec args: (cat :path (nillable? (or :string string? :file file?)))
ret: map?

file-name

([x])

Returns the name (the final path element) of x.

Spec
args: (cat :x (or :string string? :file file?))
ret: string?

hidden-file?

([x])

Checks if x is hidden (name begins with a '.' character).

Spec
args: (cat :x (or :string string? :file file?))
ret: boolean?

input-stream

([x & opts])

Attempts to coerce its argument into an open IInputStream.

list-files

([dir])

Returns a seq of the Files in dir or nil if dir is not a directory.

Spec args: (cat :dir (or :string string? :file file?))
ret: (coll-of file?)

make-input-stream

([x opts])

Creates an IInputStream. See also IOFactory docs.

make-output-stream

([x opts])
Creates an IOutputStream. See also IOFactory docs.

make-parents

([f & more])

Given the same arg(s) as for file, creates all parent directories of the file they represent.

Spec
args: (cat :path-or-parent any? :more (* any?))
ret: boolean?

make-reader

([x opts])

Creates an IReader. See also IOFactory docs.

make-writer

([x opts])

Creates an IWriter. See also IOFactory docs.

output-stream

([x & opts])

Attempts to coerce its argument into an open IOutputStream.

path-elements

([x])

Returns the path elements of x as a sequence.

Spec
args: (cat :x (or :string string? :file file?))
ret: (s/coll-of string?)

reader

([x & opts])

Attempts to coerce its argument into an open IPushbackReader.

regular-file?

([f])

Checks if f is a regular file.

Spec
args: (cat :f (or :string string? :file file?))
ret: boolean?

resource

([n])

Returns the URI for the named resource, n.

The resource must be either a JAR resource, a file resource or a "bundled" resource. JARs and files are expressed relative to the classpath while "bundled" resources are the namespaces bundled with Planck and are referred to by reference to the file that contains the namespace, eg. cljs.test is "cljs/test.cljs".

Spec
args: (cat :n (nilable string?))
ret: (nilable (instance? Uri %))

symbolic-link?

([f])

Checks if f is a symbolic link.

Spec
args: (cat :f (or :string string? :file file?))
ret: boolean?

writer

([x & opts])

Attempts to coerce its argument into an open IWriter.