Skip to main content

File

The File type represents a single file.

API reference

A file.

Implements Exportable, Node, Syncer

contents
Retrieves the contents of the file.
digest
Return the file's digest. The format of the digest is not guaranteed to be stable between releases of Dagger. It is guaranteed to be stable between invocations of the same Dagger engine.
export
Writes the file to a file path on the host.
id
A unique identifier for this File.
name
Retrieves the name of the file.
size
Retrieves the size of the file, in bytes.
asEnvFile
Parse as an env file
asJSON
Parse the file contents as JSON.
chown
Change the owner of the file recursively.
search
Searches for content matching the given regular expression or literal string.
stat
Return file status
sync
Force evaluation in the engine.
withName
Retrieves this file with its name set to the given name.
withReplaced
Retrieves the file with content replaced with the given text.
withTimestamps
Retrieves this file with its created/modified timestamps set to the given time.

contents(offsetLines: Int, limitLines: Int): String!

Retrieves the contents of the file.

offsetLines: Int

Start reading after this line

limitLines: Int

Maximum number of lines to read

digest(excludeMetadata: Boolean = false): String!

Return the file's digest. The format of the digest is not guaranteed to be stable between releases of Dagger. It is guaranteed to be stable between invocations of the same Dagger engine.

excludeMetadata: Boolean = false

If true, exclude metadata from the digest.

export(path: String!, allowParentDirPath: Boolean = false): String!

Writes the file to a file path on the host.

path: String!

Location of the written directory (e.g., "output.txt").

allowParentDirPath: Boolean = false

If allowParentDirPath is true, the path argument can be a directory path, in which case the file will be created in that directory.

id: ID!

A unique identifier for this File.

name: String!

Retrieves the name of the file.

size: Int!

Retrieves the size of the file, in bytes.

asEnvFile(expand: Boolean): EnvFile!

Parse as an env file

expand: Boolean

Replace "${VAR}" or "$VAR" with the value of other vars

asJSON: JSONValue!

Parse the file contents as JSON.

chown(owner: String!): File!

Change the owner of the file recursively.

owner: String!

A user:group to set for the file.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Searches for content matching the given regular expression or literal string.

Uses Rust regex syntax; escape literal ., [, ], {, }, | with backslashes.

pattern: String!

The text to match.

literal: Boolean = false

Interpret the pattern as a literal string instead of a regular expression.

multiline: Boolean = false

Enable searching across multiple lines.

dotall: Boolean = false

Allow the . pattern to match newlines in multiline mode.

insensitive: Boolean = false

Enable case-insensitive matching.

skipIgnored: Boolean = false

Honor .gitignore, .ignore, and .rgignore files.

skipHidden: Boolean = false

Skip hidden files (files starting with .).

filesOnly: Boolean = false

Only return matching files, not lines and content

limit: Int

Limit the number of results to return

paths: [String!] = []
globs: [String!] = []

stat: Stat

Return file status

sync: File!

Force evaluation in the engine.

withName(name: String!): File!

Retrieves this file with its name set to the given name.

name: String!

Name to set file to.

withReplaced(search: String!,replacement: String!,all: Boolean = false,firstFrom: Int): File!

Retrieves the file with content replaced with the given text.

If 'all' is true, all occurrences of the pattern will be replaced.

If 'firstAfter' is specified, only the first match starting at the specified line will be replaced.

If neither are specified, and there are multiple matches for the pattern, this will error.

If there are no matches for the pattern, this will error.

search: String!

The text to match.

replacement: String!

The text to match.

all: Boolean = false

Replace all occurrences of the pattern.

firstFrom: Int

Replace the first match starting from the specified line.

withTimestamps(timestamp: Int!): File!

Retrieves this file with its created/modified timestamps set to the given time.

timestamp: Int!

Timestamp to set dir/files in.

Formatted in seconds following Unix epoch (e.g., 1672531199).

References

Returned by

Accepted as an argument by