-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (31 loc) · 1.05 KB
/
Copy pathindex.js
File metadata and controls
34 lines (31 loc) · 1.05 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
import slice from "slice-source";
import dbf_cancel from "./cancel";
import dbf_read from "./read";
import view from "../view";
export default function(source, decoder) {
source = slice(source);
return source.slice(32).then(function(array) {
var head = view(array);
return source.slice(head.getUint16(8, true) - 32).then(function(array) {
return new Dbf(source, decoder, head, view(array));
});
});
}
function Dbf(source, decoder, head, body) {
this._source = source;
this._decode = decoder.decode.bind(decoder);
this._recordLength = head.getUint16(10, true);
this.size = head.getUint16(4, true);
this._fields = [];
for (var n = 0; body.getUint8(n) !== 0x0d; n += 32) {
for (var j = 0; j < 11; ++j) if (body.getUint8(n + j) === 0) break;
this._fields.push({
name: this._decode(new Uint8Array(body.buffer, body.byteOffset + n, j)),
type: String.fromCharCode(body.getUint8(n + 11)),
length: body.getUint8(n + 16)
});
}
}
var prototype = Dbf.prototype;
prototype.read = dbf_read;
prototype.cancel = dbf_cancel;