Home Manual Reference Source Test
public class | source

Transformer

Controls how files are transformed from and to the filesystem. Must be subclassed.

Static Member Summary

Static Public Members
public static get

The NodeTypes the transform should be applied to.

Static Method Summary

Static Public Methods
public static

encapsule(file: AtviseFile, extname: String)

Encapsules a file.

public static

encapsuledFile(file: AtviseFile, extname: String, contentString: String): AtviseFile

Takes a file and returns an encapsuled file apon it.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Creates a new Transformer based on some options

Method Summary

Public Methods
public abstract

flushFromDB(stream: NodeStream, cb: function(err: Error))

A function that is applied after all transformations passed.

public abstract

A function that is applied after all transformations passed.

public

Returns a string representation of the current Transformer.

public

transform(direction: TransformDirection): Stream

Applies transformation for a given TransformDirection.

public abstract

transformFromDB(stream: NodeStream, node: Node, enc: String, cb: function(err: Error, node: Node))

Transforms a NodeStream.

public abstract

transformFromFilesystem(stream: Stream, file: AtviseFile, enc: String, cb: function(err: Error, file: AtviseFile))

Transforms a stream of AtviseFiles.

Static Public Members

public static get applyToTypes: Map<NodeType, Boolean> source

The NodeTypes the transform should be applied to.

Static Public Methods

public static encapsule(file: AtviseFile, extname: String) source

Encapsules a file. Useful helper when splitting a file into multiple others.

Params:

NameTypeAttributeDescription
file AtviseFile

The file to encapsule.

extname String
  • optional

The file extension to use. Defaults to file's extension.

Example:

Basic usage
const file = new AtviseFile({
  path: 'path/to/file.ext'
});

// Results in a file with path 'path/to/file.ext/file.json'
Transformer.encapsule(file, '.json');

// Results in a file with path 'path/to/file.ext/file.ext'
Transformer.encapsule(file);

public static encapsuledFile(file: AtviseFile, extname: String, contentString: String): AtviseFile source

Takes a file and returns an encapsuled file apon it. Useful helper when splitting a file into multiple others. Transformer.encapsule is used to create the new file's path.

Params:

NameTypeAttributeDescription
file AtviseFile

The file to clone

extname String
  • optional

The file extension to use. Defaults to file's extension.

contentString String
  • optional

The new file's contents given as a string.

Return:

AtviseFile

The encapsuled file.

Public Constructors

public constructor(options: Object) source

Creates a new Transformer based on some options

Params:

NameTypeAttributeDescription
options Object

The options to use.

Public Methods

public abstract flushFromDB(stream: NodeStream, cb: function(err: Error)) source

A function that is applied after all transformations passed.

Params:

NameTypeAttributeDescription
stream NodeStream

The stream used.

cb function(err: Error)

Callback to call after flushing.

See:

public abstract flushFromFilesystem(stream: NodeStream, cb: function(err: Error)) source

A function that is applied after all transformations passed.

Params:

NameTypeAttributeDescription
stream NodeStream

The stream used.

cb function(err: Error)

Callback to call after flushing.

See:

public toString(): String source

Returns a string representation of the current Transformer.

Return:

String

public transform(direction: TransformDirection): Stream source

Applies transformation for a given TransformDirection.

Params:

NameTypeAttributeDescription
direction TransformDirection

The direction to use for transformation.

Return:

Stream

A stream of AtviseFiles.

public abstract transformFromDB(stream: NodeStream, node: Node, enc: String, cb: function(err: Error, node: Node)) source

Transforms a NodeStream.

Params:

NameTypeAttributeDescription
stream NodeStream

The stream used.

node Node

The node to transform.

enc String

The encoding used.

cb function(err: Error, node: Node)

Callback to call after transformation.

public abstract transformFromFilesystem(stream: Stream, file: AtviseFile, enc: String, cb: function(err: Error, file: AtviseFile)) source

Transforms a stream of AtviseFiles.

Params:

NameTypeAttributeDescription
stream Stream

The stream used.

file AtviseFile

The file to transform.

enc String

The encoding used.

cb function(err: Error, file: AtviseFile)

Callback to call after transformation.