new ResourceWriter(emitter, 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 |
---|---|---|---|
emitter |
EventEmitter |
<optional> |
|
filterFilePath |
Function |
<optional> |
|
filterFileData |
Function |
<optional> |
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 233
Fires:
- module:node-module/lib/event.event:WRITER_MKDIRP_END
- module:node-module/lib/event.event:WRITER_STREAM_START
- module:node-module/lib/event.event:WRITER_STREAM_DRAIN
- module:node-module/lib/event.event:WRITER_STREAM_ERROR
- module:node-module/lib/event.event:WRITER_STREAM_CLOSE
- module:node-module/lib/event.event:WRITER_END
Extends
- module:events.EventEmitter
Members
-
emit
-
Override EventEmitter.prototype.emit to allow for an "EventTarget-like" approach to emitting events.
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 391
-
<readonly> emitter :EventEmitter
-
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 271
-
filterFileData :Function
-
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 281
-
filterFilePath :Function
-
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 276
-
maxNumOfMkdirps :uint
-
- Since:
- 1.0
- Default Value:
- 8
- Source:
- ResourceWriter.js, line 313
-
maxNumOfStreams :uint
-
- Since:
- 1.0
- Default Value:
- 4
- Source:
- ResourceWriter.js, line 319
-
<readonly> mkdirpQueue :Queue
-
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 287
-
numOfMkdirps :uint
-
- Since:
- 1.0
- Default Value:
- 0
- Source:
- ResourceWriter.js, line 325
-
numOfStreams :uint
-
- Since:
- 1.0
- Default Value:
- 0
- Source:
- ResourceWriter.js, line 331
-
simulate :boolean
-
- Since:
- 1.0
- Default Value:
- false
- Source:
- ResourceWriter.js, line 337
-
<readonly> streamQueue :Queue
-
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 293
-
<readonly> streams :Object
-
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 299
-
<readonly> totalAsync :uint
-
- Since:
- 1.0
- Default Value:
- 0
- Source:
- ResourceWriter.js, line 344
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 361
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 410
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 424
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 440
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 467
Returns:
- Type
- string
-
reset() → {ResourceWriter}
-
Removes properties that may have been set after instantiation.
- Since:
- 1.0
- Source:
- ResourceWriter.js, line 482
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 516
Returns:
- Type
- boolean