Skip to content

Commit

Permalink
Replace binary with latin1 for ISO/IEC 8859-1 text decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Jun 29, 2024
1 parent a49df48 commit b4c8502
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/asf/AsfUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Buffer } from 'node:buffer';
import * as util from '../common/Util.js';
import { DataType } from './AsfObject.js';

export type AttributeParser = (buf: Buffer) => boolean | string | number | bigint | Buffer;
export type AttributeParser = (buf: Uint8Array) => boolean | string | number | bigint | Uint8Array;

export class AsfUtil {

Expand Down
2 changes: 1 addition & 1 deletion lib/id3v1/ID3v1Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function hasID3v1Header(reader: IRandomReader): Promise<boolean> {
if (reader.fileSize >= 128) {
const tag = Buffer.alloc(3);
await reader.randomRead(tag, 0, tag.length, reader.fileSize - 128);
return tag.toString('binary') === 'TAG';
return tag.toString('latin1') === 'TAG';
}
return false;
}
2 changes: 1 addition & 1 deletion lib/lyrics3/Lyrics3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getLyricsHeaderLength(reader: IRandomReader): Promise<numb
if (reader.fileSize >= 143) {
const buf = Buffer.alloc(15);
await reader.randomRead(buf, 0, buf.length, reader.fileSize - 143);
const txt = buf.toString('binary');
const txt = buf.toString('latin1');
const tag = txt.substr(6);
if (tag === endTag2) {
return parseInt(txt.substr(0, 6), 10) + 15;
Expand Down
2 changes: 1 addition & 1 deletion lib/riff/RiffChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Header: IGetToken<IChunkHeader> = {
get: (buf: Buffer, off): IChunkHeader => {
return {
// Group-ID
chunkID: buf.toString('binary', off, off + 4),
chunkID: buf.toString('latin1', off, off + 4),
// Size
chunkSize: Token.UINT32_LE.get(buf, 4)
};
Expand Down
2 changes: 1 addition & 1 deletion test/test-file-asf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Parse ASF', () => {
];

tests.forEach(test => {
const buf = Buffer.from(test.raw, 'binary');
const buf = new TextEncoder().encode(test.raw);
assert.strictEqual(Number(AsfUtil.getParserForAttr(DataType.QWord)(buf)), test.expected, test.description);
});

Expand Down

0 comments on commit b4c8502

Please sign in to comment.