Home Reference Source Test Repository
import FileUtil from 'typhonjs-file-util/src/FileUtil.js'
public class | source

FileUtil

FileUtil - Provides several utility methods for archiving, copying, reading, and writing files.

Constructor Summary

Public Constructor
public

constructor(options: FileUtilOptions)

Instantiate FileUtil.

Member Summary

Public Members
public

Provides a unique counter for temporary archives.

public

Stores the stack of archiver instances.

Private Members
private

_options: FileUtilOptions

Stores FileUtil options.

Method Summary

Public Methods
public

archiveCreate(destPath: string, addToParent: boolean, silent: boolean)

Create a compressed archive relative to the output destination.

public

Finalizes an active archive.

public

copy(srcPath: string, destPath: string, silent: boolean)

Copy a source path / to destination path or relative path.

public

getOptions(): FileUtilOptions

Returns a copy of the FileUtil options.

public

hydrateGlob(globs: string | Array<string>): {files: Array<string>, globs: Array<string>}

Hydrates a list of files finally defined as globs.

public

onPluginLoad(ev: PluginEvent)

Adds event bindings for FileUtil via typhonjs-plugin-manager.

public

readLines(filePath: string, lineStart: number, lineEnd: number): String[]

Read lines from a file given a start and end line number.

public

setOptions(options: FileUtilOptions)

Set optional parameters.

public

writeFile(fileData: object, filePath: string, silent: boolean, encoding: string)

Write a file to file path or relative path.

Private Methods
private

Gets the current archiver instance.

private

Pops an archiver instance off the stack.

Public Constructors

public constructor(options: FileUtilOptions) source

Instantiate FileUtil.

Params:

NameTypeAttributeDescription
options FileUtilOptions

FileUtilOptions to set.

Public Members

public archiveCntr: number source

Provides a unique counter for temporary archives.

public archiverStack: Array source

Stores the stack of archiver instances.

Private Members

private _options: FileUtilOptions source

Stores FileUtil options.

Public Methods

public archiveCreate(destPath: string, addToParent: boolean, silent: boolean) source

Create a compressed archive relative to the output destination. All subsequent file write and copy operations will add to the existing archive. You must invoke archiveFinalize to complete the archive process.

Params:

NameTypeAttributeDescription
destPath string

Destination path and file name; the compress format extension will be appended.

addToParent boolean
  • optional
  • default: true

If a parent archiver exists then add child archive to it and delete local file.

silent boolean
  • optional
  • default: false

When true output: <destPath> is logged.

public archiveFinalize(silent: boolean): Promise source

Finalizes an active archive. You must first invoke archiveCreate.

Params:

NameTypeAttributeDescription
silent boolean
  • optional
  • default: false

When true output: <destPath> is logged.

Return:

Promise

A resolved promise is returned which is triggered once archive finalization completes.

public copy(srcPath: string, destPath: string, silent: boolean) source

Copy a source path / to destination path or relative path.

Params:

NameTypeAttributeDescription
srcPath string

Source path.

destPath string

Destination path.

silent boolean
  • optional
  • default: false

When true output: <destPath> is logged.

public getOptions(): FileUtilOptions source

Returns a copy of the FileUtil options.

Return:

FileUtilOptions

FileUtil options.

public hydrateGlob(globs: string | Array<string>): {files: Array<string>, globs: Array<string>} source

Hydrates a list of files finally defined as globs. Bare directory paths will be converted to globs.

Params:

NameTypeAttributeDescription
globs string | Array<string>

A string or array of strings defining file globs. Any entry which is not a glob will be converted to an all inclusive glob.

Return:

{files: Array<string>, globs: Array<string>}

public onPluginLoad(ev: PluginEvent) source

Adds event bindings for FileUtil via typhonjs-plugin-manager.

Params:

NameTypeAttributeDescription
ev PluginEvent

A plugin event.

public readLines(filePath: string, lineStart: number, lineEnd: number): String[] source

Read lines from a file given a start and end line number.

Params:

NameTypeAttributeDescription
filePath string

The file path to load.

lineStart number

The start line

lineEnd number

The end line

Return:

String[]

public setOptions(options: FileUtilOptions) source

Set optional parameters.

Params:

NameTypeAttributeDescription
options FileUtilOptions

Defines optional parameters to set.

public writeFile(fileData: object, filePath: string, silent: boolean, encoding: string) source

Write a file to file path or relative path.

Params:

NameTypeAttributeDescription
fileData object

The file data.

filePath string

A relative file path and name to config.destination.

silent boolean
  • optional
  • default: false

When true output: <destPath> is logged.

encoding string
  • optional
  • default: utf8

The encoding type.

Private Methods

private _getArchive(): * source

Gets the current archiver instance.

Return:

*

private _popArchive(): * source

Pops an archiver instance off the stack.

Return:

*