@finsemble/finsemble-electron-adapter 1.0.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +46 -0
- package/dist/app.js +3 -0
- package/dist/app.js.LICENSE.txt +331 -0
- package/dist/app.js.map +1 -0
- package/dist/e2o.js +2 -0
- package/dist/e2o.js.map +1 -0
- package/dist/exports.js +3 -0
- package/dist/exports.js.LICENSE.txt +331 -0
- package/dist/exports.js.map +1 -0
- package/exports.js +10 -0
- package/node_modules/electron-ipc-mock/.npmignore +2 -0
- package/node_modules/electron-ipc-mock/.travis.yml +8 -0
- package/node_modules/electron-ipc-mock/LICENSE +19 -0
- package/node_modules/electron-ipc-mock/README.md +42 -0
- package/node_modules/electron-ipc-mock/dist/constants.js +8 -0
- package/node_modules/electron-ipc-mock/dist/electron-ipc-mock.js +56 -0
- package/node_modules/electron-ipc-mock/dist/event.js +25 -0
- package/node_modules/electron-ipc-mock/dist/index.js +22 -0
- package/node_modules/electron-ipc-mock/dist/ipc-main.js +103 -0
- package/node_modules/electron-ipc-mock/dist/ipc-renderer.js +113 -0
- package/node_modules/electron-ipc-mock/dist/pipe.js +40 -0
- package/node_modules/electron-ipc-mock/dist/utils.js +33 -0
- package/node_modules/electron-ipc-mock/package.json +34 -0
- package/node_modules/image-size/LICENSE +9 -0
- package/node_modules/image-size/Readme.md +182 -0
- package/node_modules/image-size/bin/image-size.js +48 -0
- package/node_modules/image-size/dist/detector.d.ts +3 -0
- package/node_modules/image-size/dist/detector.js +30 -0
- package/node_modules/image-size/dist/index.d.ts +11 -0
- package/node_modules/image-size/dist/index.js +134 -0
- package/node_modules/image-size/dist/readUInt.d.ts +4 -0
- package/node_modules/image-size/dist/readUInt.js +11 -0
- package/node_modules/image-size/dist/types/bmp.d.ts +2 -0
- package/node_modules/image-size/dist/types/bmp.js +14 -0
- package/node_modules/image-size/dist/types/cur.d.ts +2 -0
- package/node_modules/image-size/dist/types/cur.js +16 -0
- package/node_modules/image-size/dist/types/dds.d.ts +2 -0
- package/node_modules/image-size/dist/types/dds.js +14 -0
- package/node_modules/image-size/dist/types/gif.d.ts +2 -0
- package/node_modules/image-size/dist/types/gif.js +16 -0
- package/node_modules/image-size/dist/types/icns.d.ts +2 -0
- package/node_modules/image-size/dist/types/icns.js +103 -0
- package/node_modules/image-size/dist/types/ico.d.ts +2 -0
- package/node_modules/image-size/dist/types/ico.js +67 -0
- package/node_modules/image-size/dist/types/interface.d.ts +14 -0
- package/node_modules/image-size/dist/types/interface.js +2 -0
- package/node_modules/image-size/dist/types/j2c.d.ts +2 -0
- package/node_modules/image-size/dist/types/j2c.js +15 -0
- package/node_modules/image-size/dist/types/jp2.d.ts +2 -0
- package/node_modules/image-size/dist/types/jp2.js +58 -0
- package/node_modules/image-size/dist/types/jpg.d.ts +2 -0
- package/node_modules/image-size/dist/types/jpg.js +123 -0
- package/node_modules/image-size/dist/types/ktx.d.ts +2 -0
- package/node_modules/image-size/dist/types/ktx.js +15 -0
- package/node_modules/image-size/dist/types/png.d.ts +2 -0
- package/node_modules/image-size/dist/types/png.js +34 -0
- package/node_modules/image-size/dist/types/pnm.d.ts +2 -0
- package/node_modules/image-size/dist/types/pnm.js +75 -0
- package/node_modules/image-size/dist/types/psd.d.ts +2 -0
- package/node_modules/image-size/dist/types/psd.js +14 -0
- package/node_modules/image-size/dist/types/svg.d.ts +2 -0
- package/node_modules/image-size/dist/types/svg.js +91 -0
- package/node_modules/image-size/dist/types/tiff.d.ts +2 -0
- package/node_modules/image-size/dist/types/tiff.js +97 -0
- package/node_modules/image-size/dist/types/webp.d.ts +2 -0
- package/node_modules/image-size/dist/types/webp.js +58 -0
- package/node_modules/image-size/dist/types.d.ts +19 -0
- package/node_modules/image-size/dist/types.js +38 -0
- package/node_modules/image-size/package.json +67 -0
- package/node_modules/inherits/LICENSE +16 -0
- package/node_modules/inherits/README.md +42 -0
- package/node_modules/inherits/inherits.js +9 -0
- package/node_modules/inherits/inherits_browser.js +27 -0
- package/node_modules/inherits/package.json +29 -0
- package/node_modules/queue/LICENSE +8 -0
- package/node_modules/queue/index.d.ts +173 -0
- package/node_modules/queue/index.js +195 -0
- package/node_modules/queue/package.json +43 -0
- package/node_modules/queue/readme.md +221 -0
- package/package.json +119 -0
- package/types/app.d.ts +1 -0
- package/types/deploy/deploymentHelpers.d.ts +10 -0
- package/types/deploy/installer.d.ts +5 -0
- package/types/deploy/packageCreator.d.ts +4 -0
- package/types/deploy/schemas/installer.d.ts +3 -0
- package/types/deploy/schemas/packager.d.ts +3 -0
- package/types/e2o.d.ts +2 -0
- package/types/exports.d.ts +19 -0
- package/types/logger/classes/LoggerMain.d.ts +21 -0
- package/types/logger/classes/LoggerRenderer.d.ts +11 -0
- package/types/logger/colorizer.d.ts +2 -0
- package/types/logger/config.d.ts +12 -0
- package/types/logger/formatters/basic.d.ts +2 -0
- package/types/logger/main.d.ts +2 -0
- package/types/logger/renderer.d.ts +1 -0
- package/types/logger/transports/winston-daily-rotate-file.d.ts +2 -0
- package/types/logger/transports/winston-terminal-transport.d.ts +2 -0
- package/types/logger/types.d.ts +9 -0
- package/types/main/AffinityGroupManager.d.ts +15 -0
- package/types/main/BrowserViews.d.ts +38 -0
- package/types/main/ExternalApplicationManager.d.ts +37 -0
- package/types/main/IAB.d.ts +17 -0
- package/types/main/IAC.d.ts +18 -0
- package/types/main/Main.d.ts +7 -0
- package/types/main/MainBus.d.ts +22 -0
- package/types/main/MainSystem.d.ts +75 -0
- package/types/main/MainWindow.d.ts +153 -0
- package/types/main/Manifest.d.ts +13 -0
- package/types/main/MonitorInfo.d.ts +4 -0
- package/types/main/PermissionsManager.d.ts +12 -0
- package/types/main/ScreenCapture.d.ts +7 -0
- package/types/main/SplashScreen.d.ts +13 -0
- package/types/main/appDataFolder.d.ts +9 -0
- package/types/main/autoUpdaterWrapper.d.ts +37 -0
- package/types/main/contentSecurity.d.ts +17 -0
- package/types/main/contextMenu.d.ts +2 -0
- package/types/main/download.d.ts +18 -0
- package/types/main/getWindowIdentity.d.ts +3 -0
- package/types/main/listeners.d.ts +6 -0
- package/types/main/mainStore.d.ts +3 -0
- package/types/main/preloads.d.ts +9 -0
- package/types/main/protocolHandler.d.ts +11 -0
- package/types/main/updateManager.d.ts +20 -0
- package/types/permissions/chromePermissions.d.ts +59 -0
- package/types/permissions/defaultWindowOptions.d.ts +377 -0
- package/types/render/InterApplicationBus.d.ts +16 -0
- package/types/render/Notification.d.ts +3 -0
- package/types/render/RequestHelper.d.ts +23 -0
- package/types/render/System.d.ts +62 -0
- package/types/render/Window.d.ts +75 -0
- package/types/render/renderHelpers.d.ts +1 -0
- package/types/server/AppD.d.ts +18 -0
- package/types/server/AppDStaticConfigPlugin.d.ts +8 -0
- package/types/server/CosaicCloud.d.ts +21 -0
- package/types/server/Progress.d.ts +26 -0
- package/types/server/Server.d.ts +17 -0
- package/types/server/SmartDesktop.d.ts +36 -0
- package/types/server/SmartDesktopEndpoints.d.ts +99 -0
- package/types/server/SmartDesktopStaticConfigPlugin.d.ts +9 -0
- package/types/server/cssUtilities.d.ts +6 -0
- package/types/server/writeJSON.d.ts +1 -0
- package/types/startup/e2oLauncher.d.ts +1 -0
- package/types/startup/runScriptInElectron.d.ts +6 -0
- package/types/types/types.d.ts +148 -0
- package/types/util.d.ts +13 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# image-size
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/image-size/image-size)
|
|
4
|
+
[](https://www.npmjs.com/package/image-size)
|
|
5
|
+
[](http://npm-stat.com/charts.html?package=image-size&author=&from=&to=)
|
|
6
|
+
|
|
7
|
+
A [Node](https://nodejs.org/en/) module to get dimensions of any image file
|
|
8
|
+
|
|
9
|
+
## Supported formats
|
|
10
|
+
|
|
11
|
+
* BMP
|
|
12
|
+
* CUR
|
|
13
|
+
* DDS
|
|
14
|
+
* GIF
|
|
15
|
+
* ICNS
|
|
16
|
+
* ICO
|
|
17
|
+
* JPEG
|
|
18
|
+
* KTX
|
|
19
|
+
* PNG
|
|
20
|
+
* PNM (PAM, PBM, PFM, PGM, PPM)
|
|
21
|
+
* PSD
|
|
22
|
+
* SVG
|
|
23
|
+
* TIFF
|
|
24
|
+
* WebP
|
|
25
|
+
|
|
26
|
+
## Programmatic Usage
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
npm install image-size --save
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
or
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
yarn add image-size
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Synchronous
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
const sizeOf = require('image-size')
|
|
42
|
+
const dimensions = sizeOf('images/funny-cats.png')
|
|
43
|
+
console.log(dimensions.width, dimensions.height)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Asynchronous
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const sizeOf = require('image-size')
|
|
50
|
+
sizeOf('images/funny-cats.png', function (err, dimensions) {
|
|
51
|
+
console.log(dimensions.width, dimensions.height)
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
NOTE: The asynchronous version doesn't work if the input is a Buffer. Use synchronous version instead.
|
|
56
|
+
|
|
57
|
+
Also, the asynchronous functions have a default concurrency limit of **100**
|
|
58
|
+
To change this limit, you can call the `setConcurrency` function like this:
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
const sizeOf = require('image-size')
|
|
62
|
+
sizeOf.setConcurrency(123456)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Using promises (nodejs 10.x+)
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const { promisify } = require('util')
|
|
69
|
+
const sizeOf = promisify(require('image-size'))
|
|
70
|
+
sizeOf('images/funny-cats.png')
|
|
71
|
+
.then(dimensions => { console.log(dimensions.width, dimensions.height) })
|
|
72
|
+
.catch(err => console.error(err))
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Async/Await (Typescript & ES7)
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
const { promisify } = require('util')
|
|
79
|
+
const sizeOf = promisify(require('image-size'))
|
|
80
|
+
(async () => {
|
|
81
|
+
try {
|
|
82
|
+
const dimensions = await sizeOf('images/funny-cats.png')
|
|
83
|
+
console.log(dimensions.width, dimensions.height)
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(err)
|
|
86
|
+
}
|
|
87
|
+
})().then(c => console.log(c))
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Multi-size
|
|
91
|
+
|
|
92
|
+
If the target file is an icon (.ico) or a cursor (.cur), the `width` and `height` will be the ones of the first found image.
|
|
93
|
+
|
|
94
|
+
An additional `images` array is available and returns the dimensions of all the available images
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
const sizeOf = require('image-size')
|
|
98
|
+
const images = sizeOf('images/multi-size.ico').images
|
|
99
|
+
for (const dimensions of images) {
|
|
100
|
+
console.log(dimensions.width, dimensions.height)
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Using a URL
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
const url = require('url')
|
|
108
|
+
const http = require('http')
|
|
109
|
+
|
|
110
|
+
const sizeOf = require('image-size')
|
|
111
|
+
|
|
112
|
+
const imgUrl = 'http://my-amazing-website.com/image.jpeg'
|
|
113
|
+
const options = url.parse(imgUrl)
|
|
114
|
+
|
|
115
|
+
http.get(options, function (response) {
|
|
116
|
+
const chunks = []
|
|
117
|
+
response.on('data', function (chunk) {
|
|
118
|
+
chunks.push(chunk)
|
|
119
|
+
}).on('end', function() {
|
|
120
|
+
const buffer = Buffer.concat(chunks)
|
|
121
|
+
console.log(sizeOf(buffer))
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
You can optionally check the buffer lengths & stop downloading the image after a few kilobytes.
|
|
127
|
+
**You don't need to download the entire image**
|
|
128
|
+
|
|
129
|
+
### Disabling certain image types
|
|
130
|
+
```javascript
|
|
131
|
+
const imageSize = require('image-size')
|
|
132
|
+
imageSize.disableTypes(['tiff', 'ico'])
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Disabling all file-system reads
|
|
136
|
+
```javascript
|
|
137
|
+
const imageSize = require('image-size')
|
|
138
|
+
imageSize.disableFS(true)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### JPEG image orientation
|
|
142
|
+
|
|
143
|
+
If the orientation is present in the JPEG EXIF metadata, it will be returned by the function. The orientation value is a [number between 1 and 8](https://exiftool.org/TagNames/EXIF.html#:~:text=0x0112,8%20=%20Rotate%20270%20CW) representing a type of orientation.
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
const sizeOf = require('image-size')
|
|
147
|
+
const dimensions = sizeOf('images/photo.jpeg')
|
|
148
|
+
console.log(dimensions.orientation)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Command-Line Usage (CLI)
|
|
152
|
+
|
|
153
|
+
```shell
|
|
154
|
+
npm install image-size --global
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
or
|
|
158
|
+
|
|
159
|
+
```shell
|
|
160
|
+
yarn global add image-size
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
followed by
|
|
164
|
+
|
|
165
|
+
```shell
|
|
166
|
+
image-size image1 [image2] [image3] ...
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Hosted API
|
|
170
|
+
|
|
171
|
+
We also provide a hosted API for image-size which may simplify your use case.
|
|
172
|
+
|
|
173
|
+
<a href="https://image-size.saasify.sh">
|
|
174
|
+
<img src="https://badges.saasify.sh?text=View%20Hosted%20API" height="40"/>
|
|
175
|
+
</a>
|
|
176
|
+
|
|
177
|
+
## Credits
|
|
178
|
+
|
|
179
|
+
not a direct port, but an attempt to have something like
|
|
180
|
+
[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module.
|
|
181
|
+
|
|
182
|
+
## [Contributors](Contributors.md)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const { imageSize } = require('..')
|
|
7
|
+
|
|
8
|
+
const files = process.argv.slice(2)
|
|
9
|
+
|
|
10
|
+
if (!files.length) {
|
|
11
|
+
console.error('Usage: image-size image1 [image2] [image3] ...')
|
|
12
|
+
process.exit(-1)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const red = ['\x1B[31m', '\x1B[39m']
|
|
16
|
+
// const bold = ['\x1B[1m', '\x1B[22m']
|
|
17
|
+
const grey = ['\x1B[90m', '\x1B[39m']
|
|
18
|
+
const green = ['\x1B[32m', '\x1B[39m']
|
|
19
|
+
|
|
20
|
+
function colorize(text, color) {
|
|
21
|
+
return color[0] + text + color[1]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
files.forEach(function (image) {
|
|
25
|
+
try {
|
|
26
|
+
if (fs.existsSync(path.resolve(image))) {
|
|
27
|
+
const greyX = colorize('x', grey)
|
|
28
|
+
const greyImage = colorize(image, grey)
|
|
29
|
+
const size = imageSize(image)
|
|
30
|
+
const sizes = size.images || [size]
|
|
31
|
+
sizes.forEach(size => {
|
|
32
|
+
let greyType = ''
|
|
33
|
+
if (size.type) {
|
|
34
|
+
greyType = colorize(' (' + size.type + ')', grey)
|
|
35
|
+
}
|
|
36
|
+
console.info(
|
|
37
|
+
colorize(size.width, green) + greyX + colorize(size.height, green)
|
|
38
|
+
+ ' - ' + greyImage + greyType
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
} else {
|
|
42
|
+
console.error('file doesn\'t exist - ', image)
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
// console.error(e.stack)
|
|
46
|
+
console.error(colorize(e.message, red), '-', image)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detector = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const keys = Object.keys(types_1.typeHandlers);
|
|
6
|
+
// This map helps avoid validating for every single image type
|
|
7
|
+
const firstBytes = {
|
|
8
|
+
0x38: 'psd',
|
|
9
|
+
0x42: 'bmp',
|
|
10
|
+
0x44: 'dds',
|
|
11
|
+
0x47: 'gif',
|
|
12
|
+
0x49: 'tiff',
|
|
13
|
+
0x4d: 'tiff',
|
|
14
|
+
0x52: 'webp',
|
|
15
|
+
0x69: 'icns',
|
|
16
|
+
0x89: 'png',
|
|
17
|
+
0xff: 'jpg'
|
|
18
|
+
};
|
|
19
|
+
function detector(buffer) {
|
|
20
|
+
const byte = buffer[0];
|
|
21
|
+
if (byte in firstBytes) {
|
|
22
|
+
const type = firstBytes[byte];
|
|
23
|
+
if (type && types_1.typeHandlers[type].validate(buffer)) {
|
|
24
|
+
return type;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const finder = (key) => types_1.typeHandlers[key].validate(buffer);
|
|
28
|
+
return keys.find(finder);
|
|
29
|
+
}
|
|
30
|
+
exports.detector = detector;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { imageType } from './types';
|
|
3
|
+
import { ISizeCalculationResult } from './types/interface';
|
|
4
|
+
declare type CallbackFn = (e: Error | null, r?: ISizeCalculationResult) => void;
|
|
5
|
+
export default imageSize;
|
|
6
|
+
export declare function imageSize(input: Buffer | string): ISizeCalculationResult;
|
|
7
|
+
export declare function imageSize(input: string, callback: CallbackFn): void;
|
|
8
|
+
export declare const disableFS: (v: boolean) => void;
|
|
9
|
+
export declare const disableTypes: (types: imageType[]) => void;
|
|
10
|
+
export declare const setConcurrency: (c: number) => void;
|
|
11
|
+
export declare const types: string[];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.types = exports.setConcurrency = exports.disableTypes = exports.disableFS = exports.imageSize = void 0;
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
const queue_1 = require("queue");
|
|
16
|
+
const types_1 = require("./types");
|
|
17
|
+
const detector_1 = require("./detector");
|
|
18
|
+
// Maximum buffer size, with a default of 512 kilobytes.
|
|
19
|
+
// TO-DO: make this adaptive based on the initial signature of the image
|
|
20
|
+
const MaxBufferSize = 512 * 1024;
|
|
21
|
+
// This queue is for async `fs` operations, to avoid reaching file-descriptor limits
|
|
22
|
+
const queue = new queue_1.default({ concurrency: 100, autostart: true });
|
|
23
|
+
const globalOptions = {
|
|
24
|
+
disabledFS: false,
|
|
25
|
+
disabledTypes: []
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Return size information based on a buffer
|
|
29
|
+
*
|
|
30
|
+
* @param {Buffer} buffer
|
|
31
|
+
* @param {String} filepath
|
|
32
|
+
* @returns {Object}
|
|
33
|
+
*/
|
|
34
|
+
function lookup(buffer, filepath) {
|
|
35
|
+
// detect the file type.. don't rely on the extension
|
|
36
|
+
const type = (0, detector_1.detector)(buffer);
|
|
37
|
+
if (typeof type !== 'undefined') {
|
|
38
|
+
if (globalOptions.disabledTypes.indexOf(type) > -1) {
|
|
39
|
+
throw new TypeError('disabled file type: ' + type);
|
|
40
|
+
}
|
|
41
|
+
// find an appropriate handler for this file type
|
|
42
|
+
if (type in types_1.typeHandlers) {
|
|
43
|
+
const size = types_1.typeHandlers[type].calculate(buffer, filepath);
|
|
44
|
+
if (size !== undefined) {
|
|
45
|
+
size.type = type;
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// throw up, if we don't understand the file
|
|
51
|
+
throw new TypeError('unsupported file type: ' + type + ' (file: ' + filepath + ')');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reads a file into a buffer.
|
|
55
|
+
* @param {String} filepath
|
|
56
|
+
* @returns {Promise<Buffer>}
|
|
57
|
+
*/
|
|
58
|
+
function asyncFileToBuffer(filepath) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const handle = yield fs.promises.open(filepath, 'r');
|
|
61
|
+
try {
|
|
62
|
+
const { size } = yield handle.stat();
|
|
63
|
+
if (size <= 0) {
|
|
64
|
+
throw new Error('Empty file');
|
|
65
|
+
}
|
|
66
|
+
const bufferSize = Math.min(size, MaxBufferSize);
|
|
67
|
+
const buffer = Buffer.alloc(bufferSize);
|
|
68
|
+
yield handle.read(buffer, 0, bufferSize, 0);
|
|
69
|
+
return buffer;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
yield handle.close();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Synchronously reads a file into a buffer, blocking the nodejs process.
|
|
78
|
+
*
|
|
79
|
+
* @param {String} filepath
|
|
80
|
+
* @returns {Buffer}
|
|
81
|
+
*/
|
|
82
|
+
function syncFileToBuffer(filepath) {
|
|
83
|
+
// read from the file, synchronously
|
|
84
|
+
const descriptor = fs.openSync(filepath, 'r');
|
|
85
|
+
try {
|
|
86
|
+
const { size } = fs.fstatSync(descriptor);
|
|
87
|
+
if (size <= 0) {
|
|
88
|
+
throw new Error('Empty file');
|
|
89
|
+
}
|
|
90
|
+
const bufferSize = Math.min(size, MaxBufferSize);
|
|
91
|
+
const buffer = Buffer.alloc(bufferSize);
|
|
92
|
+
fs.readSync(descriptor, buffer, 0, bufferSize, 0);
|
|
93
|
+
return buffer;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
fs.closeSync(descriptor);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
100
|
+
module.exports = exports = imageSize; // backwards compatibility
|
|
101
|
+
exports.default = imageSize;
|
|
102
|
+
/**
|
|
103
|
+
* @param {Buffer|string} input - buffer or relative/absolute path of the image file
|
|
104
|
+
* @param {Function=} [callback] - optional function for async detection
|
|
105
|
+
*/
|
|
106
|
+
function imageSize(input, callback) {
|
|
107
|
+
// Handle buffer input
|
|
108
|
+
if (Buffer.isBuffer(input)) {
|
|
109
|
+
return lookup(input);
|
|
110
|
+
}
|
|
111
|
+
// input should be a string at this point
|
|
112
|
+
if (typeof input !== 'string' || globalOptions.disabledFS) {
|
|
113
|
+
throw new TypeError('invalid invocation. input should be a Buffer');
|
|
114
|
+
}
|
|
115
|
+
// resolve the file path
|
|
116
|
+
const filepath = path.resolve(input);
|
|
117
|
+
if (typeof callback === 'function') {
|
|
118
|
+
queue.push(() => asyncFileToBuffer(filepath)
|
|
119
|
+
.then((buffer) => process.nextTick(callback, null, lookup(buffer, filepath)))
|
|
120
|
+
.catch(callback));
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const buffer = syncFileToBuffer(filepath);
|
|
124
|
+
return lookup(buffer, filepath);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.imageSize = imageSize;
|
|
128
|
+
const disableFS = (v) => { globalOptions.disabledFS = v; };
|
|
129
|
+
exports.disableFS = disableFS;
|
|
130
|
+
const disableTypes = (types) => { globalOptions.disabledTypes = types; };
|
|
131
|
+
exports.disableTypes = disableTypes;
|
|
132
|
+
const setConcurrency = (c) => { queue.concurrency = c; };
|
|
133
|
+
exports.setConcurrency = setConcurrency;
|
|
134
|
+
exports.types = Object.keys(types_1.typeHandlers);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readUInt = void 0;
|
|
4
|
+
// Abstract reading multi-byte unsigned integers
|
|
5
|
+
function readUInt(buffer, bits, offset, isBigEndian) {
|
|
6
|
+
offset = offset || 0;
|
|
7
|
+
const endian = isBigEndian ? 'BE' : 'LE';
|
|
8
|
+
const methodName = ('readUInt' + bits + endian);
|
|
9
|
+
return buffer[methodName].call(buffer, offset);
|
|
10
|
+
}
|
|
11
|
+
exports.readUInt = readUInt;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BMP = void 0;
|
|
4
|
+
exports.BMP = {
|
|
5
|
+
validate(buffer) {
|
|
6
|
+
return ('BM' === buffer.toString('ascii', 0, 2));
|
|
7
|
+
},
|
|
8
|
+
calculate(buffer) {
|
|
9
|
+
return {
|
|
10
|
+
height: Math.abs(buffer.readInt32LE(22)),
|
|
11
|
+
width: buffer.readUInt32LE(18)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CUR = void 0;
|
|
4
|
+
const ico_1 = require("./ico");
|
|
5
|
+
const TYPE_CURSOR = 2;
|
|
6
|
+
exports.CUR = {
|
|
7
|
+
validate(buffer) {
|
|
8
|
+
if (buffer.readUInt16LE(0) !== 0) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return buffer.readUInt16LE(2) === TYPE_CURSOR;
|
|
12
|
+
},
|
|
13
|
+
calculate(buffer) {
|
|
14
|
+
return ico_1.ICO.calculate(buffer);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DDS = void 0;
|
|
4
|
+
exports.DDS = {
|
|
5
|
+
validate(buffer) {
|
|
6
|
+
return buffer.readUInt32LE(0) === 0x20534444;
|
|
7
|
+
},
|
|
8
|
+
calculate(buffer) {
|
|
9
|
+
return {
|
|
10
|
+
height: buffer.readUInt32LE(12),
|
|
11
|
+
width: buffer.readUInt32LE(16)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GIF = void 0;
|
|
4
|
+
const gifRegexp = /^GIF8[79]a/;
|
|
5
|
+
exports.GIF = {
|
|
6
|
+
validate(buffer) {
|
|
7
|
+
const signature = buffer.toString('ascii', 0, 6);
|
|
8
|
+
return (gifRegexp.test(signature));
|
|
9
|
+
},
|
|
10
|
+
calculate(buffer) {
|
|
11
|
+
return {
|
|
12
|
+
height: buffer.readUInt16LE(8),
|
|
13
|
+
width: buffer.readUInt16LE(6)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ICNS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* ICNS Header
|
|
6
|
+
*
|
|
7
|
+
* | Offset | Size | Purpose |
|
|
8
|
+
* | 0 | 4 | Magic literal, must be "icns" (0x69, 0x63, 0x6e, 0x73) |
|
|
9
|
+
* | 4 | 4 | Length of file, in bytes, msb first. |
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
const SIZE_HEADER = 4 + 4; // 8
|
|
13
|
+
const FILE_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
|
|
14
|
+
/**
|
|
15
|
+
* Image Entry
|
|
16
|
+
*
|
|
17
|
+
* | Offset | Size | Purpose |
|
|
18
|
+
* | 0 | 4 | Icon type, see OSType below. |
|
|
19
|
+
* | 4 | 4 | Length of data, in bytes (including type and length), msb first. |
|
|
20
|
+
* | 8 | n | Icon data |
|
|
21
|
+
*/
|
|
22
|
+
const ENTRY_LENGTH_OFFSET = 4; // MSB => BIG ENDIAN
|
|
23
|
+
const ICON_TYPE_SIZE = {
|
|
24
|
+
ICON: 32,
|
|
25
|
+
'ICN#': 32,
|
|
26
|
+
// m => 16 x 16
|
|
27
|
+
'icm#': 16,
|
|
28
|
+
icm4: 16,
|
|
29
|
+
icm8: 16,
|
|
30
|
+
// s => 16 x 16
|
|
31
|
+
'ics#': 16,
|
|
32
|
+
ics4: 16,
|
|
33
|
+
ics8: 16,
|
|
34
|
+
is32: 16,
|
|
35
|
+
s8mk: 16,
|
|
36
|
+
icp4: 16,
|
|
37
|
+
// l => 32 x 32
|
|
38
|
+
icl4: 32,
|
|
39
|
+
icl8: 32,
|
|
40
|
+
il32: 32,
|
|
41
|
+
l8mk: 32,
|
|
42
|
+
icp5: 32,
|
|
43
|
+
ic11: 32,
|
|
44
|
+
// h => 48 x 48
|
|
45
|
+
ich4: 48,
|
|
46
|
+
ich8: 48,
|
|
47
|
+
ih32: 48,
|
|
48
|
+
h8mk: 48,
|
|
49
|
+
// . => 64 x 64
|
|
50
|
+
icp6: 64,
|
|
51
|
+
ic12: 32,
|
|
52
|
+
// t => 128 x 128
|
|
53
|
+
it32: 128,
|
|
54
|
+
t8mk: 128,
|
|
55
|
+
ic07: 128,
|
|
56
|
+
// . => 256 x 256
|
|
57
|
+
ic08: 256,
|
|
58
|
+
ic13: 256,
|
|
59
|
+
// . => 512 x 512
|
|
60
|
+
ic09: 512,
|
|
61
|
+
ic14: 512,
|
|
62
|
+
// . => 1024 x 1024
|
|
63
|
+
ic10: 1024,
|
|
64
|
+
};
|
|
65
|
+
function readImageHeader(buffer, imageOffset) {
|
|
66
|
+
const imageLengthOffset = imageOffset + ENTRY_LENGTH_OFFSET;
|
|
67
|
+
return [
|
|
68
|
+
buffer.toString('ascii', imageOffset, imageLengthOffset),
|
|
69
|
+
buffer.readUInt32BE(imageLengthOffset)
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
function getImageSize(type) {
|
|
73
|
+
const size = ICON_TYPE_SIZE[type];
|
|
74
|
+
return { width: size, height: size, type };
|
|
75
|
+
}
|
|
76
|
+
exports.ICNS = {
|
|
77
|
+
validate(buffer) {
|
|
78
|
+
return ('icns' === buffer.toString('ascii', 0, 4));
|
|
79
|
+
},
|
|
80
|
+
calculate(buffer) {
|
|
81
|
+
const bufferLength = buffer.length;
|
|
82
|
+
const fileLength = buffer.readUInt32BE(FILE_LENGTH_OFFSET);
|
|
83
|
+
let imageOffset = SIZE_HEADER;
|
|
84
|
+
let imageHeader = readImageHeader(buffer, imageOffset);
|
|
85
|
+
let imageSize = getImageSize(imageHeader[0]);
|
|
86
|
+
imageOffset += imageHeader[1];
|
|
87
|
+
if (imageOffset === fileLength) {
|
|
88
|
+
return imageSize;
|
|
89
|
+
}
|
|
90
|
+
const result = {
|
|
91
|
+
height: imageSize.height,
|
|
92
|
+
images: [imageSize],
|
|
93
|
+
width: imageSize.width
|
|
94
|
+
};
|
|
95
|
+
while (imageOffset < fileLength && imageOffset < bufferLength) {
|
|
96
|
+
imageHeader = readImageHeader(buffer, imageOffset);
|
|
97
|
+
imageSize = getImageSize(imageHeader[0]);
|
|
98
|
+
imageOffset += imageHeader[1];
|
|
99
|
+
result.images.push(imageSize);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
};
|