Skip to content

Commit cfaa9d1

Browse files
committed
refactor: remove unused constants and comments
1 parent dce14ba commit cfaa9d1

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

src/commands/fs/cat.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { resolve as resolvePath } from 'path';
33
import { cwd } from 'process';
44

55
export const cat = async (path) => {
6-
await new Promise((resolve, reject) => {
6+
await new Promise((res, rej) => {
77
const filePath = resolvePath(cwd(), path);
8-
const fileContent = createReadStream(filePath, { encoding: 'utf8' });
8+
const stream = createReadStream(filePath, { encoding: 'utf8' });
99

10-
fileContent.on('data', (chunk) => {
10+
stream.on('data', (chunk) => {
1111
console.log(chunk);
1212
});
13-
fileContent.on('error', reject);
14-
fileContent.on('end', resolve);
13+
stream.on('error', rej);
14+
stream.on('end', res);
1515
});
1616
};

src/commands/fs/cp.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { createReadStream, createWriteStream } from 'fs';
2-
import { resolve as pathResolve, basename } from 'path';
2+
import { resolve, basename } from 'path';
33

44
export const cp = async (path, newPath) => {
5-
const fileToCopyPath = pathResolve(process.cwd(), path);
6-
const fileName = basename(fileToCopyPath);
7-
const dirToWritePath = pathResolve(process.cwd(), newPath);
8-
const fileToWritePath = pathResolve(dirToWritePath, fileName);
5+
const srcPath = resolve(process.cwd(), path);
6+
const fileName = basename(srcPath);
7+
const destPath = resolve(process.cwd(), newPath);
8+
const fileToWritePath = resolve(destPath, fileName);
99
try {
1010
await new Promise(async (res, rej) => {
11-
const fileToCopy = createReadStream(fileToCopyPath, { encoding: 'utf8' });
12-
const fileToWrite = createWriteStream(fileToWritePath, {
11+
const file = createReadStream(srcPath, { encoding: 'utf8' });
12+
const copy = createWriteStream(fileToWritePath, {
1313
flags: 'wx',
1414
});
1515

16-
fileToCopy.pipe(fileToWrite);
17-
fileToCopy.on('error', rej);
18-
fileToCopy.on('end', res);
16+
file.pipe(copy);
17+
file.on('error', rej);
18+
file.on('end', res);
1919
});
2020
} catch (error) {
2121
throw error;

src/commands/fs/rm.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { rm as rmFile} from 'fs/promises';
22
import { resolve } from 'path';
3-
import { cwd } from 'process';
4-
5-
import { rm_success } from '../../common/messages.js';
63

74
export const remove = async (path) => {
8-
const filePath = resolve(cwd(), path);
5+
const filePath = resolve(process.cwd(), path);
96
await rmFile(filePath);
10-
117
};

src/commands/fs/rn.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { rename } from 'fs/promises';
22
import { resolve } from 'path';
33
import { cwd } from 'process';
4-
import { rn_success } from '../../common/messages.js';
54

65
export const rn = async (currentName, newName) => {
76
const filePath = resolve(cwd(), currentName);

src/commands/zip/brotli.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import { resolve, basename, parse } from 'path';
33
import { createBrotliDecompress, createBrotliCompress } from 'zlib';
44

55
export const brotli = async (option, path, newPath) => {
6-
const EXT = 'br';
6+
const EXT = 'br';
77
try {
88
const needCompress = option === 'compress';
99

10-
const fileToConvertPath = resolve(process.cwd(), path);
10+
const filePath = resolve(process.cwd(), path);
1111

12-
const baseName = basename(fileToConvertPath);
12+
const baseName = basename(filePath);
1313
const fileName = parse(baseName).name;
1414

15-
const fileNameToWrite = needCompress ? `${baseName}.${EXT}` : fileName;
16-
const dirToWritePath = resolve(process.cwd(), newPath);
17-
const fileToWritePath = resolve(dirToWritePath, fileNameToWrite);
15+
const newFileName = needCompress ? `${baseName}.${EXT}` : fileName;
16+
const dirPath = resolve(process.cwd(), newPath);
17+
const brotliPath = resolve(dirPath, newFileName);
1818

1919
await new Promise((res, rej) => {
20-
const fileToConvert = createReadStream(fileToConvertPath);
21-
const fileToWrite = createWriteStream(fileToWritePath, { flags: 'wx',});
20+
const file = createReadStream(filePath);
21+
const brotliFile = createWriteStream(brotliPath, { flags: 'wx', });
2222

2323
const brotliHandler = needCompress ? createBrotliCompress() : createBrotliDecompress();
2424

25-
fileToConvert.pipe(brotliHandler).pipe(fileToWrite);
26-
fileToConvert.on('error', rej);
27-
fileToConvert.on('end', res);
25+
file.pipe(brotliHandler).pipe(brotliFile);
26+
file.on('error', rej);
27+
file.on('end', res);
2828
});
2929
} catch (err) {
3030
throw err;

0 commit comments

Comments
 (0)