@cloudant/couchbackup 2.11.12-SNAPSHOT-383 → 2.11.12-SNAPSHOT-384

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/includes/liner.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright © 2017, 2024 IBM Corp. All rights reserved.
1
+ // Copyright © 2017, 2025 IBM Corp. All rights reserved.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
13
13
  // limitations under the License.
14
14
 
15
15
  const { createInterface } = require('node:readline');
16
- const { PassThrough, Duplex } = require('node:stream');
16
+ const { Duplex, PassThrough, Transform } = require('node:stream');
17
17
  const debug = require('debug');
18
18
 
19
19
  /**
@@ -32,16 +32,14 @@ class Liner extends Duplex {
32
32
  log = debug(('couchbackup:liner'));
33
33
  // Flag for whether the readline interface is running
34
34
  isRunning = true;
35
+ // Flag for whether the readline interface is closed
36
+ isClosed = false;
35
37
  // Line number state
36
38
  lineNumber = 0;
37
39
  // Buffer of processed lines
38
40
  lines = [];
39
- // Stream of bytes that will be processed to lines.
40
- inStream = new PassThrough({ objectMode: false })
41
- // if there is an error destroy this Duplex with it
42
- .on('error', e => this.destroy(e));
43
41
 
44
- constructor() {
42
+ constructor(sanitize = false) {
45
43
  // Configuration of this Duplex:
46
44
  // objectMode: false on the writable input (file chunks), true on the readable output (line objects)
47
45
  // The readableHighWaterMark controls the number of lines buffered after this implementation calls
@@ -49,6 +47,25 @@ class Liner extends Duplex {
49
47
  // there is additional buffering downstream and file processing is faster than the network ops
50
48
  // we don't bottleneck here even without a large buffer.
51
49
  super({ readableObjectMode: true, readableHighWaterMark: 0, writableObjectMode: false });
50
+ // Set up the stream of bytes that will be processed to lines.
51
+ if (sanitize) {
52
+ // Handle unescaped unicode "newlines" by escaping them before passing to readline
53
+ this.inStream = new Transform({
54
+ objectMode: false,
55
+ transform(chunk, encoding, callback) {
56
+ try {
57
+ this.push(chunk.toString('utf-8').replace(/\u2028/, '\\u2028').replace(/\u2029/, '\\u2029'));
58
+ callback();
59
+ } catch (e) {
60
+ callback(e);
61
+ }
62
+ }
63
+ });
64
+ } else {
65
+ this.inStream = new PassThrough({ objectMode: false });
66
+ }
67
+ // if there is an error destroy this Duplex with it
68
+ this.inStream.on('error', e => this.destroy(e));
52
69
  // Built-in readline interface over the inStream
53
70
  this.readlineInterface = createInterface({
54
71
  input: this.inStream, // the writable side of Liner, passed through
@@ -60,7 +77,8 @@ class Liner extends Duplex {
60
77
  const bufferedLines = this.lines.push(this.wrapLine(line));
61
78
  this.log(`Liner processed line ${this.lineNumber}. Buffered lines available: ${bufferedLines}.`);
62
79
  this.pushAvailable();
63
- }).on('close', () => {
80
+ }).once('close', () => {
81
+ this.isClosed = true;
64
82
  this.log('Liner readline interface closed.');
65
83
  // Push null onto our lines buffer to signal EOF to downstream consumers.
66
84
  this.lines.push(null);
@@ -87,13 +105,16 @@ class Liner extends Duplex {
87
105
  // Check readline is running flag and whether there is content to push.
88
106
  while (this.isRunning && this.lines.length > 0) {
89
107
  if (!this.push(this.lines.shift())) {
108
+ this.log(`Back-pressure from push. Buffered lines available: ${this.lines.length}.`);
90
109
  // Push returned false, this indicates downstream back-pressure.
91
110
  // Pause the readline interface to stop pushing more lines downstream.
92
111
  // Resumption is triggered by downstream calling _read which happens
93
112
  // when it is ready for more data.
94
- this.log(`Liner pausing after back-pressure from push. Buffered lines available: ${this.lines.length}.`);
95
113
  this.isRunning = false;
96
- this.readlineInterface.pause();
114
+ if (!this.isClosed) {
115
+ this.log('Liner pausing.');
116
+ this.readlineInterface.pause();
117
+ }
97
118
  break;
98
119
  } else {
99
120
  this.log(`Liner pushed. Buffered lines available: ${this.lines.length}.`);
@@ -114,9 +135,11 @@ class Liner extends Duplex {
114
135
  // is called to ensure that pushes are able to happen (and thereby trigger)
115
136
  // subsequent reads.
116
137
  if (!this.isRunning) {
117
- this.log('Liner resuming after read.');
118
138
  this.isRunning = true;
119
- this.readlineInterface.resume();
139
+ if (!this.isClosed) {
140
+ this.log('Liner resuming after read.');
141
+ this.readlineInterface.resume();
142
+ }
120
143
  }
121
144
  this.pushAvailable();
122
145
  }
@@ -50,7 +50,7 @@ module.exports = function(dbClient, options, readstream, ee) {
50
50
 
51
51
  const batchPreparationStreams = [
52
52
  readstream, // the backup file
53
- new Liner(), // line by line
53
+ new Liner(true), // line by line (for Node.js 24 compatibility santize unicode line separators)
54
54
  new MappingStream(restore.backupLineToDocsArray), // convert line to a docs array
55
55
  new BatchingStream(options.bufferSize, true), // make new arrays of the correct buffer size
56
56
  new MappingStream(restore.docsToRestoreBatch) // make a restore batch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudant/couchbackup",
3
- "version": "2.11.12-SNAPSHOT-383",
3
+ "version": "2.11.12-SNAPSHOT-384",
4
4
  "description": "CouchBackup - command-line backup utility for Cloudant/CouchDB",
5
5
  "homepage": "https://github.com/IBM/couchbackup",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "engines": {
23
- "node": "^20 || ^22"
23
+ "node": "^20 || ^22 || ^24"
24
24
  },
25
25
  "dependencies": {
26
26
  "@ibm-cloud/cloudant": "0.12.11",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "ibm-cloud-sdk-core": "^5.4.3",
32
- "axios": "^1.12.2"
32
+ "axios": "^1.13.1"
33
33
  },
34
34
  "main": "app.js",
35
35
  "bin": {