turbodata 0.1.0
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 +201 -0
- package/NOTICE +27 -0
- package/README.md +215 -0
- package/dist/compression.d.ts +8 -0
- package/dist/compression.d.ts.map +1 -0
- package/dist/compression.js +19 -0
- package/dist/compression.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +37 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +174 -0
- package/dist/io.js.map +1 -0
- package/dist/iterators/message_heap.d.ts +17 -0
- package/dist/iterators/message_heap.d.ts.map +1 -0
- package/dist/iterators/message_heap.js +83 -0
- package/dist/iterators/message_heap.js.map +1 -0
- package/dist/iterators/preloaded_topics_group_iterator.d.ts +38 -0
- package/dist/iterators/preloaded_topics_group_iterator.d.ts.map +1 -0
- package/dist/iterators/preloaded_topics_group_iterator.js +109 -0
- package/dist/iterators/preloaded_topics_group_iterator.js.map +1 -0
- package/dist/iterators/topics_group_iterator.d.ts +45 -0
- package/dist/iterators/topics_group_iterator.d.ts.map +1 -0
- package/dist/iterators/topics_group_iterator.js +132 -0
- package/dist/iterators/topics_group_iterator.js.map +1 -0
- package/dist/loaded_bytes.d.ts +12 -0
- package/dist/loaded_bytes.d.ts.map +1 -0
- package/dist/loaded_bytes.js +43 -0
- package/dist/loaded_bytes.js.map +1 -0
- package/dist/msgpack.d.ts +10 -0
- package/dist/msgpack.d.ts.map +1 -0
- package/dist/msgpack.js +44 -0
- package/dist/msgpack.js.map +1 -0
- package/dist/multi_reader.d.ts +56 -0
- package/dist/multi_reader.d.ts.map +1 -0
- package/dist/multi_reader.js +281 -0
- package/dist/multi_reader.js.map +1 -0
- package/dist/read_fetcher.d.ts +9 -0
- package/dist/read_fetcher.d.ts.map +1 -0
- package/dist/read_fetcher.js +59 -0
- package/dist/read_fetcher.js.map +1 -0
- package/dist/read_options.d.ts +40 -0
- package/dist/read_options.d.ts.map +1 -0
- package/dist/read_options.js +16 -0
- package/dist/read_options.js.map +1 -0
- package/dist/read_planner.d.ts +37 -0
- package/dist/read_planner.d.ts.map +1 -0
- package/dist/read_planner.js +110 -0
- package/dist/read_planner.js.map +1 -0
- package/dist/read_source.d.ts +19 -0
- package/dist/read_source.d.ts.map +1 -0
- package/dist/read_source.js +15 -0
- package/dist/read_source.js.map +1 -0
- package/dist/read_strategy.d.ts +52 -0
- package/dist/read_strategy.d.ts.map +1 -0
- package/dist/read_strategy.js +70 -0
- package/dist/read_strategy.js.map +1 -0
- package/dist/reader.d.ts +209 -0
- package/dist/reader.d.ts.map +1 -0
- package/dist/reader.js +649 -0
- package/dist/reader.js.map +1 -0
- package/dist/sample.d.ts +41 -0
- package/dist/sample.d.ts.map +1 -0
- package/dist/sample.js +528 -0
- package/dist/sample.js.map +1 -0
- package/dist/sort_and_filter.d.ts +25 -0
- package/dist/sort_and_filter.d.ts.map +1 -0
- package/dist/sort_and_filter.js +126 -0
- package/dist/sort_and_filter.js.map +1 -0
- package/dist/sources/blob.d.ts +8 -0
- package/dist/sources/blob.d.ts.map +1 -0
- package/dist/sources/blob.js +38 -0
- package/dist/sources/blob.js.map +1 -0
- package/dist/sources/http.d.ts +17 -0
- package/dist/sources/http.d.ts.map +1 -0
- package/dist/sources/http.js +90 -0
- package/dist/sources/http.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
- package/src/compression.ts +28 -0
- package/src/index.ts +70 -0
- package/src/io.ts +214 -0
- package/src/iterators/message_heap.ts +104 -0
- package/src/iterators/preloaded_topics_group_iterator.ts +143 -0
- package/src/iterators/topics_group_iterator.ts +180 -0
- package/src/loaded_bytes.ts +61 -0
- package/src/msgpack.ts +46 -0
- package/src/multi_reader.ts +337 -0
- package/src/read_fetcher.ts +74 -0
- package/src/read_options.ts +58 -0
- package/src/read_planner.ts +153 -0
- package/src/read_source.ts +33 -0
- package/src/read_strategy.ts +111 -0
- package/src/reader.ts +910 -0
- package/src/sample.ts +715 -0
- package/src/sort_and_filter.ts +167 -0
- package/src/sources/blob.ts +52 -0
- package/src/sources/http.ts +121 -0
- package/src/types.ts +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one of
|
|
111
|
+
the following places: within a NOTICE text file distributed as
|
|
112
|
+
part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Wanjia He
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
turbodata
|
|
2
|
+
Copyright 2026 Wanjia He
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Wanjia He and the turbodata
|
|
5
|
+
contributors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (see the LICENSE file).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
This software depends on third-party packages that are downloaded at build
|
|
12
|
+
time and are not redistributed as part of this source tree. Each remains
|
|
13
|
+
under its own license. Notable dependencies include:
|
|
14
|
+
|
|
15
|
+
Go SDK (go/):
|
|
16
|
+
- github.com/foxglove/mcap/go/mcap (MIT)
|
|
17
|
+
- github.com/klauspost/compress (BSD-3-Clause / Apache-2.0 / MIT)
|
|
18
|
+
- github.com/vmihailenco/msgpack/v5 (BSD-2-Clause)
|
|
19
|
+
- github.com/google/go-cmp (BSD-3-Clause)
|
|
20
|
+
|
|
21
|
+
Python SDK (py/):
|
|
22
|
+
- msgpack (Apache-2.0)
|
|
23
|
+
- zstandard (BSD-3-Clause)
|
|
24
|
+
|
|
25
|
+
TypeScript SDK (ts/):
|
|
26
|
+
- @msgpack/msgpack (ISC)
|
|
27
|
+
- fzstd (MIT)
|
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# turbodata (TypeScript)
|
|
2
|
+
|
|
3
|
+
Browser TypeScript reader for the turbodata format. **Read-only** port of the
|
|
4
|
+
Go reference implementation. Built primarily so web apps (e.g. Lichtblick) can
|
|
5
|
+
load `.td`/turbodata files locally (`Blob`/`File`) or remotely (HTTP Range
|
|
6
|
+
requests). The on-disk format is identical across SDKs, so files written by Go
|
|
7
|
+
or Python read back here unchanged.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install turbodata
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
See the [top-level README](../README.md) for scope and the format overview.
|
|
14
|
+
This guide is API usage by feature: **read → sample → multi-file** (writing is
|
|
15
|
+
not supported in the browser SDK). Runnable versions of every snippet live in
|
|
16
|
+
[`examples/`](./examples).
|
|
17
|
+
|
|
18
|
+
## Numeric types
|
|
19
|
+
|
|
20
|
+
| Go field type | TS type |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `int64` (timestamps, offsets, lengths) | `bigint` |
|
|
23
|
+
| `uint8`, `uint16`, `uint32` | `number` |
|
|
24
|
+
|
|
25
|
+
This matches the convention used by `@mcap/core`. Mixing `bigint` and `number`
|
|
26
|
+
in arithmetic raises `TypeError` in JavaScript, so callers must pass `bigint`
|
|
27
|
+
values for `startTimestamp`, `endTimestamp`, etc.
|
|
28
|
+
|
|
29
|
+
## Read
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { Reader, BlobReadSource } from "turbodata";
|
|
33
|
+
|
|
34
|
+
const file: File = /* from <input type="file"> */;
|
|
35
|
+
const reader = new Reader(new BlobReadSource(file));
|
|
36
|
+
|
|
37
|
+
for await (const msg of reader.readMessages()) {
|
|
38
|
+
// msg.timestamp: bigint
|
|
39
|
+
// msg.topicName: string
|
|
40
|
+
// msg.data: Uint8Array (aliases an internal buffer; copy to persist)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Buffer aliasing
|
|
45
|
+
|
|
46
|
+
By default, `msg.data` aliases an internal reusable buffer and is only valid
|
|
47
|
+
until the next iteration step. For Lichtblick-style code that posts messages
|
|
48
|
+
to other workers, pass `{ copy: true }` to get a fresh `Uint8Array` per
|
|
49
|
+
message:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
for await (const msg of reader.readMessages({ copy: true })) { ... }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Order, time, and topic filters
|
|
56
|
+
|
|
57
|
+
Topics not listed are skipped; chunks fully outside the `[start, end]` window
|
|
58
|
+
are never fetched. Timestamps are `bigint`.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
for await (const msg of reader.readMessages({
|
|
62
|
+
order: "reverse-time", // default: "time"
|
|
63
|
+
topicNames: ["/imu", "/cam"], // default: all topics
|
|
64
|
+
startTimestamp: 1_000n, // inclusive lower bound
|
|
65
|
+
endTimestamp: 2_000n, // inclusive upper bound
|
|
66
|
+
})) { ... }
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Cost-aware reading (HTTP Range)
|
|
70
|
+
|
|
71
|
+
Pass a `strategy` to switch onto the cost-aware concurrent path — it pre-plans
|
|
72
|
+
every needed byte range, coalesces neighbors, optionally splits large reads,
|
|
73
|
+
and fetches concurrently. Without a strategy, the reader uses the default lazy
|
|
74
|
+
path. Helper constructors: `StrategyForLatency`, `StrategyForMoney`,
|
|
75
|
+
`StrategyForBlended`.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { Reader, HttpRangeReadSource, StrategyForLatency } from "turbodata";
|
|
79
|
+
|
|
80
|
+
const reader = new Reader(new HttpRangeReadSource(url));
|
|
81
|
+
for await (const msg of reader.readMessages({
|
|
82
|
+
strategy: StrategyForLatency({
|
|
83
|
+
rttSeconds: 0.05,
|
|
84
|
+
perStreamBytesPerSec: 8_000_000,
|
|
85
|
+
concurrency: 8,
|
|
86
|
+
}),
|
|
87
|
+
})) { ... }
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Video
|
|
91
|
+
|
|
92
|
+
A non-key frame is only decodable after its GOP's key frame, so a plain time
|
|
93
|
+
filter that starts mid-GOP yields bytes a decoder can't cold-start on. Pass
|
|
94
|
+
`{ videoDecodable: true }` to snap the effective `startTimestamp` back to the
|
|
95
|
+
latest key frame at or before it. Non-video topics are unaffected.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
for await (const msg of reader.readMessages({
|
|
99
|
+
topicNames: ["/cam/h264"],
|
|
100
|
+
startTimestamp: 650n, // mid-GOP
|
|
101
|
+
videoDecodable: true, // snaps back to the key frame at/<=650
|
|
102
|
+
})) { ... }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Sample (floor lookup at concrete timestamps)
|
|
106
|
+
|
|
107
|
+
`sample` returns the floor message per `(topic, timestamp)` pair: the most
|
|
108
|
+
recent message at or before each requested timestamp. `out[i][j]` corresponds
|
|
109
|
+
to `queries[i].timestamps[j]`; `found` is false when nothing precedes the
|
|
110
|
+
query. Timestamps within a query must be strictly increasing.
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const out = await reader.sample([
|
|
114
|
+
{ topic: "/imu", timestamps: [150n, 350n] },
|
|
115
|
+
{ topic: "/cam", timestamps: [1_000n, 2_000n] },
|
|
116
|
+
]);
|
|
117
|
+
for (const row of out) {
|
|
118
|
+
for (const res of row) {
|
|
119
|
+
if (res.found) console.log(res.timestamp, res.data.length);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Pass `{ strategy }` to override the default sample cost model for your backend.
|
|
125
|
+
|
|
126
|
+
### Video
|
|
127
|
+
|
|
128
|
+
With `{ videoDecodable: true }`, results for a video topic carry a
|
|
129
|
+
decoder-ready GOP sequence in `frames` (and `data` is empty) instead of the
|
|
130
|
+
single floor frame, and set `isVideo`. Within a row, the first result in each
|
|
131
|
+
GOP sets `resetDecoder: true` with the full prefix `[keyframe ... target]`;
|
|
132
|
+
later results in the same GOP carry only the new frames since the previous
|
|
133
|
+
query.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const out = await reader.sample(
|
|
137
|
+
[{ topic: "/cam", timestamps: [25n, 55n] }],
|
|
138
|
+
{ videoDecodable: true },
|
|
139
|
+
);
|
|
140
|
+
for (const res of out[0]) {
|
|
141
|
+
if (res.found) {
|
|
142
|
+
// feed res.frames to a decoder, resetting it first when res.resetDecoder.
|
|
143
|
+
console.log(res.timestamp, res.resetDecoder, res.frames.length);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Reading several files (MultiReader)
|
|
149
|
+
|
|
150
|
+
`MultiReader` presents several single-file `Reader`s as one time-ordered
|
|
151
|
+
stream. Options pass through to each underlying reader, so topic filtering,
|
|
152
|
+
time bounds, order, and strategy apply per file before the merge. Topic-name
|
|
153
|
+
collisions across files are resolved with per-`Reader` `topicRemap`: names
|
|
154
|
+
meant to union share an exposed name; names meant to stay distinct are
|
|
155
|
+
remapped apart.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { MultiReader, Reader } from "turbodata";
|
|
159
|
+
|
|
160
|
+
const mr = new MultiReader([
|
|
161
|
+
new Reader(sourceA),
|
|
162
|
+
// Keep file B's "/cam" distinct instead of unioning it with A's.
|
|
163
|
+
new Reader(sourceB, { topicRemap: { "/cam": "/cam_b" } }),
|
|
164
|
+
]);
|
|
165
|
+
|
|
166
|
+
for await (const msg of mr.readMessages()) {
|
|
167
|
+
console.log(msg.timestamp, msg.topicName);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// sample() returns, per cell, the latest floor across the union of files.
|
|
171
|
+
const out = await mr.sample([{ topic: "/cam", timestamps: [150n, 350n] }]);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Under `{ videoDecodable: true }`, any in-scope video topic supplied by more
|
|
175
|
+
than one reader must have time-disjoint source ranges; overlapping sources
|
|
176
|
+
throw `VideoSourcesOverlapError` (merging them would interleave frames from
|
|
177
|
+
different GOP chains into an undecodable stream).
|
|
178
|
+
|
|
179
|
+
### Topic remap
|
|
180
|
+
|
|
181
|
+
`topicRemap` is keyed by in-file name and valued by the exposed name reported
|
|
182
|
+
by `summary()`, emitted from `readMessages`, and accepted by `topicNames` and
|
|
183
|
+
`SampleQuery.topic`. Names absent from the map pass through unchanged. It works
|
|
184
|
+
on a single `Reader` too:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
const reader = new Reader(source, { topicRemap: { "/cam": "/cam_v2" } });
|
|
188
|
+
for await (const msg of reader.readMessages({ topicNames: ["/cam_v2"] })) {
|
|
189
|
+
console.log(msg.topicName); // "/cam_v2"
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The remap is validated lazily against the file's summary on first use: it
|
|
194
|
+
throws `TopicRemapError` if two topics collapse onto the same exposed name.
|
|
195
|
+
|
|
196
|
+
## Examples
|
|
197
|
+
|
|
198
|
+
Runnable examples live in [`examples/`](./examples). They run under Node via
|
|
199
|
+
[`tsx`](https://github.com/privatenumber/tsx) by wrapping a committed test
|
|
200
|
+
fixture's bytes in a `BlobReadSource`, so no writer step is needed:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
cd ts
|
|
204
|
+
npm install
|
|
205
|
+
npm run example:read # defaults, order, topic + time filters, strategy, video snap-back
|
|
206
|
+
npm run example:sample # floor lookup, multi-topic, strategy, video GOP-prefix
|
|
207
|
+
npm run example:multiread # union, split-via-remap, cross-file sample
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Schema metadata
|
|
211
|
+
|
|
212
|
+
The package exports `META_KEY_SCHEMA_NAME`, `META_KEY_SCHEMA_ENCODING`, and
|
|
213
|
+
`META_KEY_SCHEMA_DATA` for accessing each topic's metadata map. The first two
|
|
214
|
+
values are strings; schema data decodes as `Uint8Array`. Older files may omit
|
|
215
|
+
these keys. Reading does not warn or automatically decode message payloads.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decompress a zstd-compressed buffer. Must accept the exact bytes produced
|
|
3
|
+
* by github.com/klauspost/compress/zstd's EncodeAll (i.e. the standard zstd
|
|
4
|
+
* frame format).
|
|
5
|
+
*/
|
|
6
|
+
export type Decompressor = (compressed: Uint8Array) => Uint8Array;
|
|
7
|
+
export declare const defaultDecompressor: Decompressor;
|
|
8
|
+
//# sourceMappingURL=compression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,CAAC;AAElE,eAAO,MAAM,mBAAmB,EAAE,YAEjC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2026 Wanjia He
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// Pluggable zstd decompression. Default backend is fzstd (pure JS, sync).
|
|
15
|
+
import { decompress as fzstdDecompress } from "fzstd";
|
|
16
|
+
export const defaultDecompressor = (compressed) => {
|
|
17
|
+
return fzstdDecompress(compressed);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=compression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compression.js","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,0EAA0E;AAE1E,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,OAAO,CAAC;AAStD,MAAM,CAAC,MAAM,mBAAmB,GAAiB,CAAC,UAAU,EAAE,EAAE;IAC9D,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { Reader, SampleValidationError, TopicRemapError, DEFAULT_SAMPLE_STRATEGY, linSpaceTimestamps, } from "./reader.js";
|
|
2
|
+
export type { Frame, Message, ReaderOptions, SampleQuery, SampleResult, SampleOptions, } from "./reader.js";
|
|
3
|
+
export { MultiReader, VideoSourcesOverlapError } from "./multi_reader.js";
|
|
4
|
+
export type { ReadOptions, Order } from "./read_options.js";
|
|
5
|
+
export { MAX_INT64 } from "./read_options.js";
|
|
6
|
+
export type { ReadStrategy } from "./read_strategy.js";
|
|
7
|
+
export { StrategyForLatency, StrategyForMoney, StrategyForBlended, } from "./read_strategy.js";
|
|
8
|
+
export type { ReadSource } from "./read_source.js";
|
|
9
|
+
export { BlobReadSource } from "./sources/blob.js";
|
|
10
|
+
export { HttpRangeReadSource } from "./sources/http.js";
|
|
11
|
+
export type { HttpRangeReadSourceOptions } from "./sources/http.js";
|
|
12
|
+
export type { Decompressor } from "./compression.js";
|
|
13
|
+
export { defaultDecompressor } from "./compression.js";
|
|
14
|
+
export type { Footer, Summary, TopicsInfo, TopicMetadata, IndexChunkInfo, IndexChunk, TopicIndex, MessageIndex, } from "./types.js";
|
|
15
|
+
export { META_KEY_COMPRESSED, META_KEY_SCHEMA_NAME, META_KEY_SCHEMA_ENCODING, META_KEY_SCHEMA_DATA, META_KEY_VIDEO, META_KEY_CHUNK_CONFIG, } from "./types.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,eAAe,EACf,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,KAAK,EACL,OAAO,EACP,aAAa,EACb,WAAW,EACX,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,YAAY,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAEpE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,YAAY,EACV,MAAM,EACN,OAAO,EACP,UAAU,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,GACtB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2026 Wanjia He
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// Public API surface.
|
|
15
|
+
export { Reader, SampleValidationError, TopicRemapError, DEFAULT_SAMPLE_STRATEGY, linSpaceTimestamps, } from "./reader.js";
|
|
16
|
+
export { MultiReader, VideoSourcesOverlapError } from "./multi_reader.js";
|
|
17
|
+
export { MAX_INT64 } from "./read_options.js";
|
|
18
|
+
export { StrategyForLatency, StrategyForMoney, StrategyForBlended, } from "./read_strategy.js";
|
|
19
|
+
export { BlobReadSource } from "./sources/blob.js";
|
|
20
|
+
export { HttpRangeReadSource } from "./sources/http.js";
|
|
21
|
+
export { defaultDecompressor } from "./compression.js";
|
|
22
|
+
export { META_KEY_COMPRESSED, META_KEY_SCHEMA_NAME, META_KEY_SCHEMA_ENCODING, META_KEY_SCHEMA_DATA, META_KEY_VIDEO, META_KEY_CHUNK_CONFIG, } from "./types.js";
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,sBAAsB;AAEtB,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,eAAe,EACf,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAIxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAYvD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,qBAAqB,GACtB,MAAM,YAAY,CAAC"}
|
package/dist/io.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { FOOTER_LEN, type Footer, type IndexChunk, type IndexChunkInfo, type MessageIndex, type Summary, type TopicIndex, type TopicMetadata, type TopicsInfo } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Forward-only cursor over a Uint8Array. The Go reader uses io.Reader+
|
|
4
|
+
* binary.Read; here we expose the equivalent calls. All reads are big-endian.
|
|
5
|
+
*
|
|
6
|
+
* We deliberately do NOT support seeking; everything in the format is
|
|
7
|
+
* sequentially decodable from a known start point.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BinaryReader {
|
|
10
|
+
private readonly view;
|
|
11
|
+
private readonly bytes;
|
|
12
|
+
private off;
|
|
13
|
+
constructor(bytes: Uint8Array);
|
|
14
|
+
get offset(): number;
|
|
15
|
+
get remaining(): number;
|
|
16
|
+
private require;
|
|
17
|
+
readUint8(): number;
|
|
18
|
+
readUint16(): number;
|
|
19
|
+
readUint32(): number;
|
|
20
|
+
readInt64(): bigint;
|
|
21
|
+
readBytes(n: number): Uint8Array;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse a fixed-size (13-byte) footer.
|
|
25
|
+
*
|
|
26
|
+
* Layout: 8-byte int64 SummaryLen, then 5-byte Magic.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readFooter(r: BinaryReader): Footer;
|
|
29
|
+
export declare function readTopicMetadata(r: BinaryReader): TopicMetadata;
|
|
30
|
+
export declare function readIndexChunkInfo(r: BinaryReader): IndexChunkInfo;
|
|
31
|
+
export declare function readTopicsInfo(r: BinaryReader): TopicsInfo;
|
|
32
|
+
export declare function readSummary(r: BinaryReader): Summary;
|
|
33
|
+
export declare function readMessageIndex(r: BinaryReader): MessageIndex;
|
|
34
|
+
export declare function readTopicIndex(r: BinaryReader): TopicIndex;
|
|
35
|
+
export declare function readIndexChunk(r: BinaryReader): IndexChunk;
|
|
36
|
+
export { FOOTER_LEN };
|
|
37
|
+
//# sourceMappingURL=io.d.ts.map
|
package/dist/io.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,UAAU,EACV,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AAQpB;;;;;;GAMG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,GAAG,CAAS;gBAER,KAAK,EAAE,UAAU;IAM7B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,OAAO,CAAC,OAAO;IAQf,SAAS,IAAI,MAAM;IAOnB,UAAU,IAAI,MAAM;IAOpB,UAAU,IAAI,MAAM;IAOpB,SAAS,IAAI,MAAM;IAOnB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU;CAMjC;AAwBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,CAKlD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,YAAY,GAAG,aAAa,CAMhE;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,GAAG,cAAc,CAKlE;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,GAAG,UAAU,CAa1D;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAOpD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,GAAG,YAAY,CAI9D;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,GAAG,UAAU,CAa1D;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,GAAG,UAAU,CAU1D;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|