forked from luoxuhai/pcl.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystem.test.ts
48 lines (40 loc) · 1.39 KB
/
FileSystem.test.ts
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
41
42
43
44
45
46
47
48
import fs from 'fs';
import path from 'path';
import * as PCL from '../../';
describe('FileSystem', () => {
const text = '# .PCD v.7 - Point Cloud Data file format';
it('should write and read files', () => {
const binary = fs.readFileSync(path.join(global.ROOT_DIR, '/data/room_scan2.pcd'));
PCL.fs.writeFile('test-write-file.pcd', text);
PCL.fs.writeFile('test-write-binary-file.pcd', new Uint8Array(binary));
const textRes = PCL.fs.readFile('test-write-file.pcd', {
encoding: 'utf8',
});
const binaryRes = PCL.fs.readFile('test-write-binary-file.pcd') as Uint8Array;
expect(textRes).toBe(text);
expect(binaryRes?.byteLength).toBe(binary.byteLength);
});
it('should read a file information', () => {
PCL.fs.writeFile('test-read-file-info.pcd', text);
const pcd = PCL.fs.stat('test-read-file-info.pcd');
expect(pcd?.size).toBe(41);
});
it('should create a folder', () => {
PCL.fs.mkdir('new-folder');
const result = PCL.fs.stat('new-folder');
expect(result?.size).toBe(4096);
expect(result?.isDir).toBe(true);
});
it('should delete a file', () => {
const filename = 'test-write-file-1.pcd';
PCL.fs.writeFile(filename, 'text');
PCL.fs.unlink(filename);
let result: any = null;
try {
result = PCL.fs.stat(filename);
} catch {
result = undefined;
}
expect(result).toBeUndefined();
});
});