Skip to content

@ui5/fs/Resource

@ui5/fs/Resource

Resource. UI5 CLI specific representation of a file's content and metadata

Constructor

new @ui5/fs/Resource(parameters)

Source: fs/lib/Resource.js, line 49

Parameters:
NameTypeDescription
parametersobjectParameters
Properties:
NameTypeAttributesDescription
pathstringAbsolute virtual path of the resource
statInfofs.Stats | objectoptionalFile information. Instance of
fs.Stats or similar object
bufferBufferoptionalContent of this resources as a Buffer instance
(cannot be used in conjunction with parameters string, stream or createStream)
stringstringoptionalContent of this resources as a string
(cannot be used in conjunction with parameters buffer, stream or createStream)
streamStreamoptionalReadable stream of the content of this resource
(cannot be used in conjunction with parameters buffer, string or createStream)
createBuffer@ui5/fs/Resource~createBufferoptionalFunction callback that returns a promise
resolving with a Buffer of the content of this resource (cannot be used in conjunction with
parameters buffer, string or stream). Must be used in conjunction with parameters createStream.
createStream@ui5/fs/Resource~createStreamoptionalFunction callback that returns a readable
stream of the content of this resource (cannot be used in conjunction with parameters buffer,
string or stream).
In some cases this is the most memory-efficient way to supply resource content
project@ui5/project/specifications/ProjectoptionalProject this resource is associated with
sourceMetadataobjectoptionalSource metadata for UI5 CLI internal use.
Some information may be set by an adapter to store information for later retrieval. Also keeps track of whether
a resource content has been modified since it has been read from a source
isDirectorybooleanoptionalFlag whether the resource represents a directory
byteSizenumberoptionalSize of the resource content in bytes
lastModifiednumberoptionalLast modified timestamp (in milliseconds since UNIX epoch)
integritystringoptionalIntegrity hash of the resource content
inodenumberoptionalInode number of the resource

Methods

(async) clone() → {Promise<@ui5/fs/Resource>}

Description: Returns a clone of the resource. The clones content is independent from that of the original resource

Source: fs/lib/Resource.js, line 797

Returns:

Promise resolving with the clone

Type: Promise<@ui5/fs/Resource>

(async) getBuffer() → {Promise<Buffer>}

Description: Gets a buffer with the resource content.

Source: fs/lib/Resource.js, line 255

Returns:

Promise resolving with a buffer of the resource content.

Type: Promise<Buffer>

getInode() → {number}

Description: Gets the inode number of the resource.

Source: fs/lib/Resource.js, line 744

Returns:

Inode number of the resource

Type: number

getLastModified() → {number}

Description: Gets the last modified timestamp of the resource.

Source: fs/lib/Resource.js, line 734

Returns:

Last modified timestamp (in milliseconds since UNIX epoch)

Type: number

getName() → {string}

Description: Gets the resource name

Source: fs/lib/Resource.js, line 694

Returns:

Name of the resource

Type: string

getOriginalPath() → {string}

Description: Gets the virtual resources path

Source: fs/lib/Resource.js, line 669

Returns:

(Virtual) path of the resource

Type: string

getPath() → {string}

Description: Gets the virtual resources path

Source: fs/lib/Resource.js, line 659

Returns:

Virtual path of the resource

Type: string

Description: Retrieve the project assigned to the resource
Note for UI5 CLI extensions (i.e. custom tasks, custom middleware): In order to ensure compatibility across UI5 CLI versions, consider using the getProject(resource) method provided by TaskUtil and MiddlewareUtil, which will return a Specification Version-compatible Project interface.

Source: fs/lib/Resource.js, line 854

Returns:

Project this resource is associated with

Type: @ui5/project/specifications/Project

(async) getSize() → {Promise<number>}

Description: Resource content size in bytes.

Source: fs/lib/Resource.js, line 755

See:

Returns:

size in bytes, 0 if the resource has no content

Type: Promise<number>

getStatInfo() → {fs.Stats|object}

Description: Gets the resources stat info. Note that a resources stat information is not updated when the resource is being modified. Also, depending on the used adapter, some fields might be missing which would be present for a fs.Stats instance.

Source: fs/lib/Resource.js, line 709

Deprecated: Use dedicated APIs like Resource.getSize(), .isDirectory(), .getLastModified() instead

Returns:

Instance of fs.Stats or similar object

Type: fs.Stats | object

getStream() → {stream.Readable}

Description: Gets a readable stream for the resource content.

Repetitive calls of this function are only possible if new content has been set in the meantime (through setStream, setBuffer or setString). This is to prevent subsequent consumers from accessing drained streams.

This method is deprecated. Please use the asynchronous version getStreamAsync instead.

For atomic operations, consider using modifyStream.

Source: fs/lib/Resource.js, line 359

Deprecated: Use asynchronous Resource.getStreamAsync() instead

Returns:

Readable stream for the resource content.

Type: stream.Readable

(async) getStreamAsync() → {Promise<stream.Readable>}

Description: Gets a readable stream for the resource content.

Repetitive calls of this function are only possible if new content has been set in the meantime (through setStream, setBuffer or setString). This is to prevent subsequent consumers from accessing drained streams.

For atomic operations, consider using modifyStream.

Source: fs/lib/Resource.js, line 394

Returns:

Promise resolving with a readable stream for the resource content.

Type: Promise<stream.Readable>

(async) getString() → {Promise<string>}

Description: Gets a string with the resource content.

Source: fs/lib/Resource.js, line 327

Returns:

Promise resolving with the resource content.

Type: Promise<string>

hasProject() → {boolean}

Description: Check whether a project has been assigned to the resource

Source: fs/lib/Resource.js, line 878

Returns:

True if the resource is associated with a project

Type: boolean

hasSize() → {boolean}

Description: Checks whether the resource size can be determined without reading the entire content. E.g. for buffer-based content or if the size has been provided when the resource was created.

Source: fs/lib/Resource.js, line 774

Returns:

True if size can be determined statically

Type: boolean

isDirectory() → {boolean}

Description: Checks whether the resource represents a directory.

Source: fs/lib/Resource.js, line 724

Returns:

True if resource is a directory

Type: boolean

isModified() → {boolean}

Description: Check whether the content of this resource has been changed during its life cycle

Source: fs/lib/Resource.js, line 888

Returns:

True if the resource's content has been changed

Type: boolean

setBuffer(buffer)

Description: Sets a Buffer as content.

Source: fs/lib/Resource.js, line 312

Parameters:
NameTypeDescription
bufferBufferBuffer instance

setPath(path)

Description: Sets the virtual resources path

Source: fs/lib/Resource.js, line 679

Parameters:
NameTypeDescription
pathstringAbsolute virtual path of the resource

setProject(project)

Description: Assign a project to the resource

Source: fs/lib/Resource.js, line 864

Parameters:
NameTypeDescription
project@ui5/project/specifications/ProjectProject this resource is associated with

setStream(stream)

Description: Sets a readable stream as content.

Source: fs/lib/Resource.js, line 538

Parameters:
NameTypeDescription
streamstream.Readable | @ui5/fs/Resource~createStreamReadable stream of the resource content or
callback for dynamic creation of a readable stream

setString(string)

Description: Sets a String as content

Source: fs/lib/Resource.js, line 338

Parameters:
NameTypeDescription
stringstringResource content

Type Definitions

createStream() → {stream.Readable}

Description: Factory function to dynamic (and potentially repeated) creation of readable streams of the resource's content

Source: fs/lib/Resource.js, line 77

Returns:

A readable stream of the resource's content

Type: stream.Readable