(obj, opts = {})
| 100 | // regular files that POSIX local filesystems do, so the removal above is |
| 101 | // equally valid on Windows. No platform-specific code is needed here. |
| 102 | function jsonlLineForWrite(obj, opts = {}) { |
| 103 | const line = JSON.stringify(obj) + '\n'; |
| 104 | const maxLineBytes = Math.max(1, Math.floor(Number(opts.maxLineBytes) || resolveMaxJsonlLineBytes())); |
| 105 | const lineBytes = Buffer.byteLength(line, 'utf8'); |
| 106 | if (lineBytes > maxLineBytes) { |
| 107 | const err = new Error(`mailbox JSONL line is ${lineBytes} bytes; maximum is ${maxLineBytes} bytes`); |
| 108 | err.code = 'MAILBOX_JSONL_LINE_TOO_LARGE'; |
| 109 | err.lineBytes = lineBytes; |
| 110 | err.maxLineBytes = maxLineBytes; |
| 111 | throw err; |
| 112 | } |
| 113 | return line; |
| 114 | } |
| 115 | |
| 116 | function appendLine(filePath, obj) { |
| 117 | const line = jsonlLineForWrite(obj); |
no test coverage detected