-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxpm.js
More file actions
29 lines (24 loc) · 697 Bytes
/
xpm.js
File metadata and controls
29 lines (24 loc) · 697 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
import {lazystream} from '../util.js';
export function readMediaAttributes(input) {
const stream = lazystream(input);
const result = {
width: 0,
height: 0,
size: stream.size(),
mime: 'image/x-xpixmap',
};
const target = '[] = {\n';
const startIndex = stream.indexOf(target);
const [widthString, heightString] = stream
.skip(startIndex + target.length)
.takeLine()
.toString()
.replace(/[^\d\s]/g, '')
.split(/\s+/);
if (widthString && heightString) {
result.width = parseInt(widthString);
result.height = parseInt(heightString);
}
stream.close();
return result;
}