ssh2-scp 1.0.2 → 1.1.0

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.
@@ -277,23 +277,23 @@ class SshFs {
277
277
  const fileSize = parseInt(fileSizeOutput.trim(), 10);
278
278
  if (fileSize <= chunkSize) {
279
279
  const output = await this.runCmd(`cat "${remotePath}"`);
280
- return Buffer.from(output, "binary");
280
+ return output;
281
281
  }
282
282
  const chunks = [];
283
283
  for (let offset = 0; offset < fileSize; offset += chunkSize) {
284
284
  const cmd = `dd if="${remotePath}" bs=1K skip=${Math.floor(offset / 1024)} count=${Math.ceil(chunkSize / 1024)} 2>/dev/null`;
285
285
  const chunkOutput = await this.runCmd(cmd);
286
286
  if (chunkOutput) {
287
- chunks.push(Buffer.from(chunkOutput, "binary"));
287
+ chunks.push(chunkOutput);
288
288
  }
289
289
  }
290
- return Buffer.concat(chunks);
290
+ return chunks.join("");
291
291
  }
292
292
  async writeFile(remotePath, str, mode, _options) {
293
- const data = typeof str === "string" ? Buffer.from(str) : str;
293
+ const data = Buffer.from(str);
294
294
  const sizeThreshold = 64 * 1024;
295
295
  if (data.length <= sizeThreshold) {
296
- const escapedContent = data.toString("binary").replace(/'/g, "'\\''");
296
+ const escapedContent = str.replace(/'/g, "'\\''");
297
297
  const cmd = `printf '%s' '${escapedContent}' > "${remotePath}"`;
298
298
  await this.runCmd(cmd);
299
299
  } else {
@@ -53,8 +53,8 @@ export declare class SshFs {
53
53
  rm(remotePath: string): Promise<string>;
54
54
  readFile(remotePath: string, options?: {
55
55
  chunkSize?: number;
56
- }): Promise<Buffer>;
57
- writeFile(remotePath: string, str: Buffer | string, mode?: number, _options?: {
56
+ }): Promise<string>;
57
+ writeFile(remotePath: string, str: string, mode?: number, _options?: {
58
58
  chunkSize?: number;
59
59
  }): Promise<void>;
60
60
  }
@@ -275,23 +275,23 @@ class SshFs {
275
275
  const fileSize = parseInt(fileSizeOutput.trim(), 10);
276
276
  if (fileSize <= chunkSize) {
277
277
  const output = await this.runCmd(`cat "${remotePath}"`);
278
- return Buffer.from(output, "binary");
278
+ return output;
279
279
  }
280
280
  const chunks = [];
281
281
  for (let offset = 0; offset < fileSize; offset += chunkSize) {
282
282
  const cmd = `dd if="${remotePath}" bs=1K skip=${Math.floor(offset / 1024)} count=${Math.ceil(chunkSize / 1024)} 2>/dev/null`;
283
283
  const chunkOutput = await this.runCmd(cmd);
284
284
  if (chunkOutput) {
285
- chunks.push(Buffer.from(chunkOutput, "binary"));
285
+ chunks.push(chunkOutput);
286
286
  }
287
287
  }
288
- return Buffer.concat(chunks);
288
+ return chunks.join("");
289
289
  }
290
290
  async writeFile(remotePath, str, mode, _options) {
291
- const data = typeof str === "string" ? Buffer.from(str) : str;
291
+ const data = Buffer.from(str);
292
292
  const sizeThreshold = 64 * 1024;
293
293
  if (data.length <= sizeThreshold) {
294
- const escapedContent = data.toString("binary").replace(/'/g, "'\\''");
294
+ const escapedContent = str.replace(/'/g, "'\\''");
295
295
  const cmd = `printf '%s' '${escapedContent}' > "${remotePath}"`;
296
296
  await this.runCmd(cmd);
297
297
  } else {
@@ -51,8 +51,8 @@ declare class SshFs {
51
51
  rm(remotePath: string): Promise<string>;
52
52
  readFile(remotePath: string, options?: {
53
53
  chunkSize?: number;
54
- }): Promise<Buffer>;
55
- writeFile(remotePath: string, str: Buffer | string, mode?: number, _options?: {
54
+ }): Promise<string>;
55
+ writeFile(remotePath: string, str: string, mode?: number, _options?: {
56
56
  chunkSize?: number;
57
57
  }): Promise<void>;
58
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh2-scp",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Remote file system operations over SSH2 session without SFTP",
5
5
  "scripts": {
6
6
  "build": "npm run build:esm && npm run build:cjs",