Skip to content

Commit befead9

Browse files
committed
api functions
1 parent cb1c2f5 commit befead9

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const { stat } = require('fs/promises');
22
const path = require('path');
3-
const {promises: fs, constants } = require('fs');
3+
const { promises: fs, constants } = require('fs');
44
const { promisify } = require('util');
55
const execFile = promisify(require('child_process').execFile);
66

7-
const { spawn, paths, exists } = require('./util');
7+
const { spawn, paths, exists } = require('./shared');
88

99
(async () => {
1010
if (await exists(paths.exeFinal)) {

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function dumpSymbolsSync(filePath: string, cb: (e: Error, b: Buffer) => void): void;
2+
function dumpSymbols(filePath: string): Promise<Buffer>;

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { exists, paths, spawn } = require('./shared')
2+
const { promisify } = require('util');
3+
4+
const dumpSymbolSync = function (binaryPath, callback) {
5+
exists(paths.exeFinal)
6+
.then(binExists => {
7+
if (!binExists) {
8+
throw new Error('Unable to find "dump_syms"');
9+
}
10+
11+
return spawn(paths.exeFinal, [binaryPath]);
12+
})
13+
.then(b => callback(null, b))
14+
.catch(e => callback(e, null))
15+
}
16+
17+
module.exports.dumpSymbolSync = dumpSymbolSync;
18+
module.exports.dumpSymbol = promisify(dumpSymbolSync);

util.js renamed to shared.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ const spawn = (...args) => new Promise((resolve, reject) => {
66
let stdout = Buffer.alloc(0);
77
let stderr = Buffer.alloc(0);
88
const child = spawnSync(...args);
9-
const concat = (o) => (b) => o = Buffer.concat([o, b]);
10-
child.stdout.on('data', concat(stdout));
11-
child.stderr.on('data', concat(stderr));
9+
child.stdout.on('data', (b) => stdout = Buffer.concat([stdout, b]));
10+
child.stderr.on('data', (b) => stderr = Buffer.concat([stderr, b]));
1211
child.on('close', function (code) {
1312
if (code !== 0) {
1413
reject(stderr ? new Error(stderr.toString()) : new Error(`Command ${command} failed ${code}`));

0 commit comments

Comments
 (0)