Skip to content

Commit

Permalink
remove magic numbers + remove _
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Young committed Feb 21, 2024
1 parent 61be9b7 commit 5b49cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/src/id3/getId3Frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { isId3Footer } from './util/isId3Footer.js';
import { isId3Header } from './util/isId3Header.js';
import { readId3Size } from './util/readId3Size.js';

const HEADER_FOOTER_SIZE = 10;
const FRAME_SIZE = 10;

/**
* Returns an array of ID3 frames found in all the ID3 tags in the id3Data
*
Expand All @@ -24,10 +27,10 @@ export function getId3Frames(id3Data: Uint8Array): Id3Frame[] {
while (isId3Header(id3Data, offset)) {
const size = readId3Size(id3Data, offset + 6);
// skip past ID3 header
offset += 10;
offset += HEADER_FOOTER_SIZE;
const end = offset + size;
// loop through frames in the ID3 tag
while (offset + 8 < end) {
while (offset + FRAME_SIZE < end) {
const frameData: RawId3Frame = getId3FrameData(id3Data.subarray(offset));
const frame: Id3Frame | undefined = decodeId3Frame(frameData);
if (frame) {
Expand All @@ -39,7 +42,7 @@ export function getId3Frames(id3Data: Uint8Array): Id3Frame[] {
}

if (isId3Footer(id3Data, offset)) {
offset += 10;
offset += HEADER_FOOTER_SIZE;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/test/structuredfield/decodeId3TextFrame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('decodeId3TextFrame', () => {
const frame = {
type: 'TXXX',
data: new Uint8Array([0, 102, 111, 111, 0, 97, 98, 99]),
size: 2, // required by the _decodeTextFrame function
size: 2, // required by the decodeTextFrame function
};

const testables = {
Expand Down

0 comments on commit 5b49cbb

Please sign in to comment.