Skip to content

Commit 478599d

Browse files
committed
refactor: update stream pipeline
1 parent 6915b19 commit 478599d

3 files changed

Lines changed: 23 additions & 41 deletions

File tree

lib/commands/generate/ssh/decrypt.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { pipeline } from "node:stream/promises";
12
import { decryptSsh } from "#core/crypto";
2-
import { pipeline } from "#core/stream";
33
import Command from "#lib/command";
44

55
export default class extends Command {
@@ -34,14 +34,8 @@ export default class extends Command {
3434
"outputEncoding": process.cli.options[ "output-encoding" ],
3535
} );
3636

37-
return new Promise( resolve =>
38-
pipeline( stream, process.stdout, e => {
39-
if ( e ) {
40-
resolve( result.catch( e, { "log": false } ) );
41-
}
42-
else {
43-
resolve( result( 200 ) );
44-
}
45-
} ) );
37+
return pipeline( stream, process.stdout )
38+
.then( () => result( 200 ) )
39+
.catch( e => result.catch( e, { "log": false } ) );
4640
}
4741
}

lib/commands/generate/ssh/encrypt.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { pipeline } from "node:stream/promises";
12
import { encryptSsh } from "#core/crypto";
2-
import { pipeline } from "#core/stream";
33
import Command from "#lib/command";
44

55
export default class extends Command {
@@ -34,14 +34,8 @@ export default class extends Command {
3434
"outputEncoding": process.cli.options[ "output-encoding" ],
3535
} );
3636

37-
return new Promise( resolve =>
38-
pipeline( stream, process.stdout, e => {
39-
if ( e ) {
40-
resolve( result.catch( e, { "log": false } ) );
41-
}
42-
else {
43-
resolve( result( 200 ) );
44-
}
45-
} ) );
37+
return pipeline( stream, process.stdout )
38+
.then( () => result( 200 ) )
39+
.catch( e => result.catch( e, { "log": false } ) );
4640
}
4741
}

lib/debian-repository.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "#core/result";
22
import childProcess from "node:child_process";
33
import fs from "node:fs";
44
import path from "node:path";
5-
import { pipeline } from "node:stream";
5+
import { pipeline } from "node:stream/promises";
66
import { fileURLToPath } from "node:url";
77
import zlib from "node:zlib";
88
import Ajv from "#core/ajv";
@@ -206,16 +206,13 @@ export default class DebianRepository {
206206
fs.writeFileSync( this.root + `/dists/${ codename }/${ this.config.component }/binary-all/Packages`, res.data.stdout );
207207

208208
// make "Packages.gz"
209-
await new Promise( resolve => {
210-
pipeline(
211-
fs.createReadStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-all/Packages` ),
212-
zlib.createGzip( {
213-
"level": 9,
214-
} ),
215-
fs.createWriteStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-all/Packages.gz` ),
216-
e => {}
217-
).on( "close", resolve );
218-
} );
209+
await pipeline(
210+
fs.createReadStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-all/Packages` ),
211+
zlib.createGzip( {
212+
"level": 9,
213+
} ),
214+
fs.createWriteStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-all/Packages.gz` )
215+
);
219216

220217
const architectures = (
221218
await glob( "binary-*", {
@@ -247,16 +244,13 @@ export default class DebianRepository {
247244
fs.writeFileSync( this.root + `/dists/${ codename }/${ this.config.component }/binary-${ architecture }/Packages`, res.data.stdout );
248245

249246
// make "Packages.gz"
250-
await new Promise( resolve => {
251-
pipeline(
252-
fs.createReadStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-${ architecture }/Packages` ),
253-
zlib.createGzip( {
254-
"level": 9,
255-
} ),
256-
fs.createWriteStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-${ architecture }/Packages.gz` ),
257-
e => {}
258-
).on( "close", resolve );
259-
} );
247+
await pipeline(
248+
fs.createReadStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-${ architecture }/Packages` ),
249+
zlib.createGzip( {
250+
"level": 9,
251+
} ),
252+
fs.createWriteStream( this.root + `/dists/${ codename }/${ this.config.component }/binary-${ architecture }/Packages.gz` )
253+
);
260254
}
261255

262256
fs.writeFileSync(

0 commit comments

Comments
 (0)