-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathopen_vsimem.test.js
84 lines (80 loc) · 2.45 KB
/
open_vsimem.test.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const gdal = require('../lib/gdal.js')
const path = require('path')
const fs = require('fs')
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const assert = chai.assert
chai.use(chaiAsPromised)
describe('Open', () => {
afterEach(gc)
describe('vsimem', () => {
let filename, ds, ds2, buffer
after(() => {
ds.close()
})
it('should not throw', () => {
filename = path.join(__dirname, 'data/park.geo.json')
buffer = fs.readFileSync(filename)
ds = gdal.open(buffer)
})
it('should be able to read band count', () => {
assert.equal(ds.layers.count(), 1)
})
it('should keep the buffer in the dataset', () => {
assert.instanceOf(ds.buffer, Buffer)
assert.equal(ds.buffer, buffer)
})
it('should throw on an empty buffer', () => {
const buffer = Buffer.alloc(0)
assert.throws(() => gdal.open(buffer))
})
it('should throw on an invalid buffer', () => {
const buffer = Buffer.alloc(1024)
assert.throws(() => gdal.open(buffer))
})
it('should be shareable across datasets', () => {
const ds2 = gdal.open(buffer)
assert.equal(ds2.buffer, ds.buffer)
ds2.close()
})
describe('layer', () => {
let layer
before(() => {
layer = ds.layers.get(0)
})
it('should have all fields defined', () => {
assert.equal(layer.fields.count(), 3)
assert.deepEqual(layer.fields.getNames(), [
'kind',
'name',
'state'
])
})
})
})
describe('vsimem/Async', () => {
// Not supported on GDAL 1.x
if (parseFloat(gdal.version) < 2) return
let filename, ds, buffer
it('should not throw', () => {
filename = path.join(__dirname, 'data/park.geo.json')
buffer = fs.readFileSync(filename)
ds = gdal.openAsync(buffer)
})
it('should be able to read band count', () => {
assert.eventually.equal(ds.then((ds) => ds.layers.count()), 1)
})
it('should keep the buffer in the dataset', () => {
assert.eventually.instanceOf(ds.then((ds) => ds.buffer), Buffer)
assert.eventually.equal(ds.then((ds) => ds.buffer), buffer)
})
it('should throw on an empty buffer', () => {
buffer = Buffer.alloc(0)
assert.isRejected(gdal.openAsync(buffer))
})
it('should throw on an invalid buffer', () => {
buffer = Buffer.alloc(1024)
assert.isRejected(gdal.openAsync(buffer))
})
})
})