Class: ResourceWriter

ResourceWriter

new ResourceWriter(filterFilePath, filterFileData)

Object responsible for the multiple asynchronous processes of writing many files, of various size, and to various directory level locations. It wraps the functionality of the mkdirp module, and also manages many instances of fs.WriteStream.
Parameters:
Name Type Argument Description
filterFilePath Function <optional>
filterFileData Function <optional>
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 282
Fires:

Extends

  • module:events.EventEmitter

Namespaces

event

Members

filterFileData :Function

Since:
  • 1.0
Source:
  • ResourceWriter.js, line 324

filterFilePath :Function

Since:
  • 1.0
Source:
  • ResourceWriter.js, line 319

maxNumOfMkdirps :uint

Since:
  • 1.0
Default Value:
  • 8
Source:
  • ResourceWriter.js, line 356

maxNumOfStreams :uint

Since:
  • 1.0
Default Value:
  • 4
Source:
  • ResourceWriter.js, line 362

<readonly> mkdirpQueue :Queue

Since:
  • 1.0
Source:
  • ResourceWriter.js, line 330

numOfMkdirps :uint

Since:
  • 1.0
Default Value:
  • 0
Source:
  • ResourceWriter.js, line 368

numOfStreams :uint

Since:
  • 1.0
Default Value:
  • 0
Source:
  • ResourceWriter.js, line 374

simulate :boolean

Since:
  • 1.0
Default Value:
  • false
Source:
  • ResourceWriter.js, line 380

<readonly> streamQueue :Queue

Since:
  • 1.0
Source:
  • ResourceWriter.js, line 336

<readonly> streams :Object

Since:
  • 1.0
Source:
  • ResourceWriter.js, line 342

<readonly> totalAsync :uint

Since:
  • 1.0
Default Value:
  • 0
Source:
  • ResourceWriter.js, line 387

Methods

destroyStream(file) → {void}

Prepare an instance of fs.WriteSteam, retrieved by the file path it is writing to, to be removed from memory.
Parameters:
Name Type Description
file string
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 404
Returns:
Type
void

getActiveStream(file) → {module:fs.WriteStream}

Retrieve an instance of fs.WriteSteam by the file path that it is currently writing to.
Parameters:
Name Type Description
file string
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 436
Returns:
Type
module:fs.WriteStream

getFilesWritten(relativeFrom) → {string}

This is a helper method to retrieve an array of strings that represent the files this instance has written.
Parameters:
Name Type Description
relativeFrom string
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 450
Returns:
Type
string

getFilteredPath(file) → {string}

When using the module:node-samson/lib/ResourceWriter#filterFilePath callback, this method is able to retrieve the filtered or new file path, by passing its corresponding unfilered or original file path.
Parameters:
Name Type Description
file string
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 466
Returns:
Type
string

getUnfilteredPath(file) → {string}

When using the module:node-samson/lib/ResourceWriter#filterFilePath callback, this method is able to retrieve the unfiltered or original file path, by its corresponding filered or new file path.
Parameters:
Name Type Description
file string
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 493
Returns:
Type
string

reset() → {ResourceWriter}

Removes properties that may have been set after instantiation.
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 508
Returns:
Type
ResourceWriter

write(file, data) → {boolean}

This method behaves similarly to fs.WriteStream#write in that it returns false if the stream failed to write and is waiting to drain. But it also includes the extra steps of invoking mkdirp and stepping through the filters of module:node-samson/lib/ResourceWriter#filterFilePath and module:node-samson/lib/ResourceWriter#filterFileData. Since working with streams objects happens internally within thismethod, each unique file path argument represents a different instance of fs.WriteStream. This method always expects the unfiltered file path, and internally maps to stream objects that write to filtered file path locations.
Parameters:
Name Type Description
file string
data string
Since:
  • 1.0
Source:
  • ResourceWriter.js, line 542
Returns:
Type
boolean