rotating-file-stream: Example use of generator fails with "write after end" error.

The example use of a generator function in the documentation fails with “write after end” error:

Simple program to reproduce this is:

var rfs    = require('rotating-file-stream');

function pad(num) {
    return (num > 9 ? "" : "0") + num;
}

function generator(time, index) {
    if(! time)
        return "file.log";

    var month  = time.getFullYear() + "" + pad(time.getMonth() + 1);
    var day    = pad(time.getDate());
    var hour   = pad(time.getHours());
    var minute = pad(time.getMinutes());

    return "/storage/" + month + "/" + month +
        day + "-" + hour + minute + "-" + index + "-file.log";
}

var stream = rfs(generator, {
    size:     '1M',
    interval: '30m'
});

setInterval(function () {
    stream.write('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
}, 10);

Using node 8.4.0 on Bash on Windows 10.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 23 (10 by maintainers)

Most upvoted comments

Hi @normancarcamo ,

your generator function takes not care neither of parameter index nor of parameter time (apart from first check).

Please pay attention to the note of this paragraph: https://www.npmjs.com/package/rotating-file-stream#function-filenametime-index returned rotated file name must be function of both parameters time and index.

Hope this helps, iCC