[Vuejs]-NodeJS: SSH2 – Read last 1000 letters from stream

0πŸ‘

βœ…

I simply call on my β€˜on Data’ event a separate function and copy the data/chunks to a string. When I recreate my terminal component, I initialize the content with the buffer string. Also, I can watch if my "buffer" is too full and slice it.
If someone gets in the same situation, here is a example:

stream.on('data', (data) => {
    ...
    this.buffer(data)
})
...
buffer(data) {
    this.streamBuffer += data // Saving data/chunks

    const bufferLength = this.streamBuffer.length
    if (bufferLength > 10000) {
        this.streamBuffer = this.streamBuffer.slice(bufferLength - 8000)
    }
}

Leave a comment