Skip to content

Commit 1b3cdd9

Browse files
committed
flatten graphic header
1 parent 6ad59c4 commit 1b3cdd9

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v0.3.0
2+
## Breaking Changes
3+
- Flatten graphic header to an array of packets and omit page and length values
4+
15
# v0.2.0
26
## Breaking Changes
37
- Parsers no longer return delimeters, block lengths, or IDs as these are internally evaluated and checked during the parsing process

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nexrad-level-3-data",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "Parsing of NEXRAD level 3 data files",
55
"main": "src/index.js",
66
"scripts": {

src/headers/graphic.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,30 @@ const parse = (raf) => {
1111
if (blockLength < 1 || blockLength > 65535) throw new Error(`Invalid block length ${blockLength}`);
1212
if ((blockLength + raf.getPos() - 8) > raf.getLength()) throw new Error(`Block length ${blockLength} overruns file length for block id: ${blockId}`);
1313

14-
const result = {
15-
numberPages: raf.readShort(),
16-
pages: [],
17-
};
14+
const numberPages = raf.readShort();
1815

19-
if (result.numberPages < 1 || result.numberPages > 48 - 1) throw new Error(`Invalid graphic number of pages: ${result.numberPages}`);
16+
const packets = [];
17+
18+
if (numberPages < 1 || numberPages > 48 - 1) throw new Error(`Invalid graphic number of pages: ${numberPages}`);
2019

2120
// read each page
22-
for (let pageNum = 0; pageNum < result.numberPages; pageNum += 1) {
23-
const page = {
24-
number: raf.readShort(),
25-
length: raf.readShort(),
26-
packets: [],
27-
};
21+
for (let pageNum = 0; pageNum < numberPages; pageNum += 1) {
22+
const pageNumber = raf.readShort();
23+
const pageLength = raf.readShort();
2824

2925
// calculate end byte
30-
const endByte = raf.getPos() + page.length;
26+
const endByte = raf.getPos() + pageLength;
3127

3228
// test page number
33-
if (pageNum + 1 !== page.number) throw new Error(`Invalid page number: ${page.number}`);
29+
if (pageNum + 1 !== pageNumber) throw new Error(`Invalid page number: ${pageNumber}`);
3430

3531
// loop through all packets
3632
while (raf.getPos() < endByte) {
37-
page.packets.push(parser(raf));
33+
packets.push(parser(raf));
3834
}
39-
40-
result.pages.push(page);
4135
}
4236

43-
return result;
37+
return packets;
4438
};
4539

4640
//

0 commit comments

Comments
 (0)