file-timestamp-stream
Advanced tools
Comparing version 0.1.0 to 0.2.0
# Changelog | ||
## v0.2.0 2018-02-02 | ||
* Only public interface of Writable is used. | ||
* Implemented `_destroy` method which cleans up file stream. | ||
## v0.1.0 2017-10-24 | ||
@@ -4,0 +9,0 @@ |
@@ -14,13 +14,13 @@ /// <reference types="node" /> | ||
export class FileTimestampStream extends Writable { | ||
options: Options | ||
readonly options: Options | ||
flags: string | ||
fs: typeof fs | ||
newFilename: () => string | ||
path: string | ||
readonly flags: string | ||
readonly fs: typeof fs | ||
readonly newFilename: () => string | ||
readonly path: string | ||
currentFilename: string | ||
stream: Writable | ||
currentFilename?: string | ||
stream?: Writable | ||
constructor (options: Options) | ||
constructor (options?: Options) | ||
} |
@@ -21,4 +21,8 @@ 'use strict' | ||
this.currentFilename = null | ||
this.stream = null | ||
this.currentFilename = undefined | ||
this.stream = undefined | ||
this._streamErrorHandler = (err) => { | ||
this.emit('error', err) | ||
} | ||
} | ||
@@ -32,3 +36,5 @@ | ||
this.stream.end() | ||
this.stream.removeListener('error', this._streamErrorHandler) | ||
} | ||
this.stream = this.fs.createWriteStream(newFilename, { | ||
@@ -38,2 +44,5 @@ flags: this.flags, | ||
}) | ||
this.stream.on('error', this._streamErrorHandler) | ||
this.currentFilename = newFilename | ||
@@ -46,17 +55,15 @@ } | ||
this._rotate(encoding) | ||
// call private method (bypass additional buffers) | ||
return this.stream._write(chunk, encoding, callback) | ||
this.stream.write(chunk, encoding, callback) | ||
} catch (e) { | ||
return callback(e) | ||
callback(e) | ||
} | ||
} | ||
_writev (chunks, callback) { | ||
try { | ||
this._rotate('buffer') | ||
// call private method (not supported before node 4.0?) | ||
return this.stream._writev(chunks, callback) | ||
} catch (e) { | ||
return callback(e) | ||
_destroy (err, callback) { | ||
if (this.stream) { | ||
this.stream.destroy() | ||
this.stream.removeListener('error', this._streamErrorHandler) | ||
this.stream = undefined | ||
} | ||
super._destroy(err, callback) | ||
} | ||
@@ -63,0 +70,0 @@ } |
{ | ||
"name": "file-timestamp-stream", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Writing stream with file rotating based on timestamp", | ||
@@ -5,0 +5,0 @@ "main": "lib/file-timestamp-stream.js", |
@@ -48,11 +48,6 @@ ## file-timestamp-stream | ||
### Warning | ||
This module uses internal API of `fs.WriteStream`: `_write` and `_writev` | ||
methods directly for maximal performance. | ||
### License | ||
Copyright (c) 2017 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
Copyright (c) 2017-2018 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
[MIT](https://opensource.org/licenses/MIT) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7588
85
0
53