Skip to content

Commit e767eed

Browse files
authored
Fix: info command not parsing metadata on Windows (#28)
1 parent f3fd13d commit e767eed

File tree

7 files changed

+15
-8
lines changed

7 files changed

+15
-8
lines changed

src/chdman/chdmanInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default {
5656
}
5757
}
5858

59-
const metadata = [...output.matchAll(/metadata: +(.+)\n +(.+)/gi)]
59+
const metadata = [...output.matchAll(/metadata: +(.+)\r?\n +(.+)/gi)]
6060
.map((match, index_) => {
6161
const tag = match[1].match(/tag='([\d a-z]+)'/i)?.at(1)?.trim() ?? '';
6262
const index = Number.parseInt(
@@ -76,7 +76,7 @@ export default {
7676
});
7777

7878
const metadataTags = new Set(metadata.map((m) => m.tag));
79-
let type = CHDType.UNKNOWN;
79+
let type = CHDType.RAW;
8080
if (metadataTags.has('GDDD')) {
8181
type = CHDType.HARD_DISK;
8282
} else if (metadataTags.has('CHCD') || metadataTags.has('CHTR') || metadataTags.has('CHT2')) {

src/chdman/common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ export enum CHDType {
1919
GD_ROM,
2020
DVD_ROM,
2121
// LASER_DISC,
22-
UNKNOWN,
2322
}

test/chdman/chdmanBin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ChdmanBin from '../../src/chdman/chdmanBin.js';
22

3-
test('should print the help message', async () => {
3+
it('should print the help message', async () => {
44
try {
55
await ChdmanBin.run(['help']);
66
} catch (error) {

test/chdman/chdmanCd.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import fs from 'node:fs';
55
import ChdmanCd from '../../src/chdman/chdmanCd.js';
66
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
77
import TestUtil from '../testUtil.js';
8+
import { CHDType } from '../../src/chdman/common.js';
89

9-
test('should fail on nonexistent file', async () => {
10+
it('should fail on nonexistent file', async () => {
1011
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
1112
const temporaryCue = `${temporaryChd}.cue`;
1213
const temporaryBin = `${temporaryChd}.bin`;
@@ -60,6 +61,7 @@ test.each([
6061
expect(info.ratio).toBeGreaterThan(0);
6162
expect(info.sha1).toBeTruthy();
6263
expect(info.dataSha1).toBeTruthy();
64+
expect(info.type).toEqual(CHDType.CD_ROM);
6365

6466
await ChdmanCd.extractCd({
6567
inputFilename: temporaryChd,

test/chdman/chdmanDvd.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import crypto from 'node:crypto';
66
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
77
import TestUtil from '../testUtil.js';
88
import ChdmanDvd from '../../src/chdman/chdmanDvd.js';
9+
import { CHDType } from '../../src/chdman/common.js';
910

1011
// https://unix.stackexchange.com/a/33634
1112

12-
test('should fail on nonexistent file', async () => {
13+
it('should fail on nonexistent file', async () => {
1314
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
1415
const temporaryIso = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.iso`;
1516

@@ -58,6 +59,7 @@ test.each([
5859
expect(info.ratio).toBeGreaterThan(0);
5960
expect(info.sha1).toBeTruthy();
6061
expect(info.dataSha1).toBeTruthy();
62+
expect(info.type).toEqual(CHDType.DVD_ROM);
6163

6264
await ChdmanDvd.extractDvd({
6365
inputFilename: temporaryChd,

test/chdman/chdmanHd.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import fs from 'node:fs';
55
import ChdmanHd from '../../src/chdman/chdmanHd.js';
66
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
77
import TestUtil from '../testUtil.js';
8+
import { CHDType } from '../../src/chdman/common.js';
89

910
// https://unix.stackexchange.com/a/33634
1011

11-
test('should fail on nonexistent file', async () => {
12+
it('should fail on nonexistent file', async () => {
1213
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
1314
const temporaryHd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.hd`;
1415

@@ -60,6 +61,7 @@ test.each([
6061
expect(info.ratio).toBeGreaterThan(0);
6162
expect(info.sha1).toBeTruthy();
6263
expect(info.dataSha1).toBeTruthy();
64+
expect(info.type).toEqual(CHDType.HARD_DISK);
6365

6466
await ChdmanHd.extractHd({
6567
inputFilename: temporaryChd,

test/chdman/chdmanRaw.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import fs from 'node:fs';
55
import ChdmanInfo from '../../src/chdman/chdmanInfo.js';
66
import TestUtil from '../testUtil.js';
77
import ChdmanRaw from '../../src/chdman/chdmanRaw.js';
8+
import { CHDType } from '../../src/chdman/common.js';
89

9-
test('should fail on nonexistent file', async () => {
10+
it('should fail on nonexistent file', async () => {
1011
const temporaryChd = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.chd`;
1112
const temporaryRaw = `${await TestUtil.mktemp(path.join(os.tmpdir(), 'dummy'))}.hd`;
1213

@@ -61,6 +62,7 @@ test.each([
6162
expect(info.ratio).toBeGreaterThan(0);
6263
expect(info.sha1).toBeTruthy();
6364
expect(info.dataSha1).toBeTruthy();
65+
expect(info.type).toEqual(CHDType.RAW);
6466

6567
await ChdmanRaw.extractRaw({
6668
inputFilename: temporaryChd,

0 commit comments

Comments
 (0)