You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-25Lines changed: 29 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,27 +3,31 @@ streamroller
3
3
4
4
node.js file streams that roll over when they reach a maximum size, or a date/time.
5
5
6
-
npm install streamroller
6
+
```sh
7
+
npm install streamroller
8
+
```
7
9
8
10
## usage
9
11
10
-
var rollers = require('streamroller');
11
-
var stream = new rollers.RollingFileStream('myfile', 1024, 3);
12
-
stream.write("stuff");
13
-
stream.end();
12
+
```javascript
13
+
var rollers =require('streamroller');
14
+
var stream =newrollers.RollingFileStream('myfile', 1024, 3);
15
+
stream.write("stuff");
16
+
stream.end();
17
+
```
14
18
15
19
The streams behave the same as standard node.js streams, except that when certain conditions are met they will rename the current file to a backup and start writing to a new file.
16
20
17
21
### new RollingFileStream(filename [, maxSize, numBackups, options])
18
-
*`filename`(String)
19
-
*`maxSize`- the size in bytes to trigger a rollover, if not provided this defaults to MAX_SAFE_INTEGER and the stream will not roll.
20
-
*`numBackups` - the number of old files to keep (excluding the hot file)
21
-
*`options`- Object
22
-
*`encoding` - defaults to 'utf8'
23
-
*`mode` - defaults to 0644
24
-
*`flags` - defaults to 'a' (see [fs.open](https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details)
25
-
*`compress`- (boolean) defaults to `false` - compress the backup files using gzip (files will have `.gz` extension).
26
-
*`keepFileExt`- (boolean) defaults to `false` - keep the file original extension. e.g.: `abc.log -> abc.1.log`.
22
+
*`filename`\<string\>
23
+
*`maxSize`\<integer\> - defaults to `MAX_SAFE_INTEGER` - the size in bytes to trigger a rollover
24
+
*`numBackups`\<integer\> - defaults to `1`- the number of old files to keep (excluding the hot file)
25
+
*`options`\<Object\>
26
+
*`encoding`\<string\>- defaults to `'utf8'`
27
+
*`mode`\<integer\>- defaults to `0o644`
28
+
*`flags`\<string\>- defaults to `'a'` (see [fs.open](https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details)
29
+
*`compress`\<boolean\> - defaults to `false` - compress the backup files using gzip (files will have `.gz` extension).
30
+
*`keepFileExt`\<boolean\> - defaults to `false` - keep the file original extension. e.g.: `abc.log -> abc.1.log`.
27
31
28
32
This returns a `WritableStream`. When the current file being written to (given by `filename`) gets up to or larger than `maxSize`, then the current file will be renamed to `filename.1` and a new file will start being written to. Up to `numBackups` of old files are maintained, so if `numBackups` is 3 then there will be 4 files:
29
33
<pre>
@@ -41,17 +45,17 @@ When filename size >= maxSize then:
41
45
filename is a new file
42
46
</pre>
43
47
44
-
### new DateRollingFileStream(filename, pattern, options)
45
-
*`filename`(String)
46
-
*`pattern`(String) - the date pattern to trigger rolling (see below)
47
-
*`options`- Object
48
-
* `encoding` - defaults to 'utf8'
49
-
* `mode` defaults to 0644
50
-
* `flags` defaults to 'a' (see [fs.open](https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details)
51
-
* `compress` - (boolean) compress the backup files, defaults to false
52
-
* `keepFileExt` - (boolean) defaults to `false` - keep the file original extension. e.g.: `abc.log -> abc.2013-08-30.log`.
53
-
* `alwaysIncludePattern` - (boolean) extend the initial file with the pattern, defaults to false
54
-
*`daysToKeep`- (integer) the number of old files that matches the pattern to keep (excluding the hot file)
48
+
### new DateRollingFileStream(filename[, pattern, options])
49
+
*`filename`\<string\>
50
+
*`pattern`\<string\> - defaults to `yyyy-MM-dd` - the date pattern to trigger rolling (see below)
51
+
*`options`\<Object\>
52
+
*`encoding`\<string\>- defaults to `'utf8'`
53
+
*`mode`\<integer\> - defaults to `0o644`
54
+
*`flags`\<string\> - defaults to `'a'` (see [fs.open](https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details)
55
+
*`compress`\<boolean\> - defaults to `false` - compress the backup files using gzip (files will have `.gz` extension).
56
+
*`keepFileExt`\<boolean\> - defaults to `false` - keep the file original extension. e.g.: `abc.log -> abc.2013-08-30.log`.
57
+
*`alwaysIncludePattern`\<boolean\> - defaults to `false` - extend the initial file with the pattern
58
+
*`daysToKeep`\<integer\> - defaults to `MAX_SAFE_INTEGER` - the number of old files that matches the pattern to keep (excluding the hot file)
55
59
56
60
57
61
This returns a `WritableStream`. When the current time, formatted as `pattern`, changes then the current file will be renamed to `filename.formattedDate` where `formattedDate` is the result of processing the date through the pattern, and a new file will begin to be written. Streamroller uses [date-format](http://github.com/nomiddlename/date-format) to format dates, and the `pattern` should use the date-format format. e.g. with a `pattern` of `".yyyy-MM-dd"`, and assuming today is August 29, 2013 then writing to the stream today will just write to `filename`. At midnight (or more precisely, at the next file write after midnight), `filename` will be renamed to `filename.2013-08-29` and a new `filename` will be created. If `options.alwaysIncludePattern` is true, then the initial file will be `filename.2013-08-29` and no renaming will occur at midnight, but a new file will be written to with the name `filename.2013-08-30`.
0 commit comments