-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (37 loc) · 1.04 KB
/
Copy pathindex.js
File metadata and controls
40 lines (37 loc) · 1.04 KB
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
// index.js - 主模組入口
const addon = require('./build/Release/sifaddon.node');
/**
* 解析 SIF 文件並返回 JSON 數據
* @param {string} filename - SIF 文件路徑
* @returns {Object} 包含光譜數據和元數據的對象
* @throws {Error} 當文件無法解析時拋出錯誤
*/
function parseSifFile(filename) {
try {
const jsonString = addon.sifFileToJson(filename);
return JSON.parse(jsonString);
} catch (error) {
throw new Error(`Failed to parse SIF file '${filename}': ${error.message}`);
}
}
/**
* 快速檢查 SIF 文件信息
* @param {string} filename - SIF 文件路徑
* @returns {Object} 基本信息對象
*/
function getFileInfo(filename) {
const data = parseSifFile(filename);
return {
camera: data.metadata.cameraModel,
dimensions: data.dimensions,
frames: data.metadata.numberOfFrames,
exposureTime: data.metadata.exposureTime,
dataPoints: data.data.length
};
}
module.exports = {
parseSifFile,
getFileInfo,
// 保持向後兼容
sifFileToJson: addon.sifFileToJson
};