forked from SidOfc/leather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfit.js
More file actions
40 lines (32 loc) · 912 Bytes
/
fit.js
File metadata and controls
40 lines (32 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {lazystream} from '../util.js';
export function attributes(input) {
const stream = lazystream(input);
const result = {
width: 0,
height: 0,
size: stream.size(),
mime: 'image/fits',
};
let offset = 0;
while (stream.more()) {
const label = stream
.goto(offset * 80)
.takeUntil(0x20)
.toString();
if (label === 'NAXIS1' || label === 'NAXIS2') {
const property = label === 'NAXIS1' ? 'width' : 'height';
result[property] = parseInt(
stream
.goto(offset * 80)
.skip(24)
.take(8)
.toString()
.trim()
);
if (result.width !== 0 && result.height !== 0) break;
}
offset += 1;
}
stream.close();
return result;
}