gpxkit 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +5 -1
- data/SPECIFICATION.md +1 -1
- data/lib/gpxkit/version.rb +1 -1
- data/lib/gpxkit/xml/source.rb +29 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 346e6144f0b148b0a11a36b36c8b635b2b205878af2e106dbf80dd68b4389c90
|
|
4
|
+
data.tar.gz: d52e9b0307dbc255a2ae497519c2d9234ad8547304176784a40a918adf44cb10
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40df7694f7e8e797983de2275894577cc2bd48d7d6b451ab749d31103cfb3303e46ab9322763a346e47925818bd80d766e6826b9de69cfda38625ffb8e11847f
|
|
7
|
+
data.tar.gz: 2dd8e7f0471dfc3e547624574aafe731d012605649dad99ad9ec9939e72da5c1199fcb935949a16dc3d23cb0850487b073c186df68c3fdf0bf953ac6b794a842
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
Fixes from an external review of tcxkit, which shares this reader's input handling.
|
|
6
|
+
|
|
7
|
+
- A UTF-8 byte order mark split across reads, from an IO that hands over a few bytes at a time, made a valid file invalid; so did a UTF-16 file read a byte at a time. The reader now reads such an IO until it has the bytes asked for, and the DTD check waits for a whole byte order mark. Files and `StringIO` were not affected, and a DTD was never parsed.
|
|
8
|
+
- `bench/read_24h.rb` reproduces the README's timing on a synthetic 24-hour file.
|
|
9
|
+
|
|
3
10
|
## 0.1.0
|
|
4
11
|
|
|
5
12
|
First release: a read-only, streaming reader for GPX 1.1 and 1.0 files, with typed messages and fields, the common fitness extensions, enforced limits, refusal of DTDs, and an `Activity` view in the shape of `FitKit::Activity`. Requires Ruby 3.1 and Nokogiri 1.17.
|
data/README.md
CHANGED
|
@@ -84,7 +84,11 @@ Test fixtures must be synthetic. Never commit real tracks: they contain location
|
|
|
84
84
|
|
|
85
85
|
## Performance
|
|
86
86
|
|
|
87
|
-
Reading streams, so memory stays flat however long the file is (the `Activity` view keeps every message, by design). A one-hour activity reads in well under a second. A synthetic 24-hour file with a point every second takes about 9 s of CPU time on a laptop; set `limits: { max_seconds: ... }` for untrusted files.
|
|
87
|
+
Reading streams, so memory stays flat however long the file is (the `Activity` view keeps every message, by design). A one-hour activity reads in well under a second. A synthetic 24-hour file with a point every second (26 MB) takes about 9 s of CPU time on a laptop; set `limits: { max_seconds: ... }` for untrusted files. To time it yourself:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
bundle exec ruby -Ilib bench/read_24h.rb
|
|
91
|
+
```
|
|
88
92
|
|
|
89
93
|
## Releasing
|
|
90
94
|
|
data/SPECIFICATION.md
CHANGED
|
@@ -86,7 +86,7 @@ end
|
|
|
86
86
|
|
|
87
87
|
Same contract as `FitKit::Reader` and `TcxKit::Reader`:
|
|
88
88
|
|
|
89
|
-
- `Reader.new(source, close_io: false, source_label: nil, limits: Limits::DEFAULT)`. `source` is a path, a `Pathname` or an IO-like object that responds to `read`. A `Pathname` is read as a path even though it responds to `read`.
|
|
89
|
+
- `Reader.new(source, close_io: false, source_label: nil, limits: Limits::DEFAULT)`. `source` is a path, a `Pathname` or an IO-like object that responds to `read`. A `Pathname` is read as a path even though it responds to `read`. An IO that hands over fewer bytes than asked for (a socket, a decompressing stream) is read again until it has them or ends, so it reads the same as a file.
|
|
90
90
|
- `each_message` streams, and returns an Enumerator without a block.
|
|
91
91
|
- Seekable sources can be iterated again; a non-seekable IO can be read once, and a second iteration raises `Error`.
|
|
92
92
|
- Caller-owned IO is closed only with `close_io: true`.
|
data/lib/gpxkit/version.rb
CHANGED
data/lib/gpxkit/xml/source.rb
CHANGED
|
@@ -76,7 +76,7 @@ module GpxKit
|
|
|
76
76
|
@pending ||= prefix
|
|
77
77
|
return nil if @error
|
|
78
78
|
|
|
79
|
-
data = @pending.empty? ?
|
|
79
|
+
data = @pending.empty? ? read_full(length) : take(length)
|
|
80
80
|
return nil if data.nil? || @error
|
|
81
81
|
|
|
82
82
|
unless @delivered
|
|
@@ -89,6 +89,21 @@ module GpxKit
|
|
|
89
89
|
|
|
90
90
|
private
|
|
91
91
|
|
|
92
|
+
# Reads up to length bytes, reading again when the IO hands over fewer
|
|
93
|
+
# (as a socket or a decompressing stream may) until there are length
|
|
94
|
+
# bytes or the input ends. libxml2 misreads some inputs handed over a
|
|
95
|
+
# byte at a time, such as UTF-16.
|
|
96
|
+
def read_full(length)
|
|
97
|
+
data = read_raw(length)
|
|
98
|
+
while data && data.bytesize < length
|
|
99
|
+
return refuse(time_limit_error) if @clock.exceeded?
|
|
100
|
+
|
|
101
|
+
more = read_raw(length - data.bytesize) or break
|
|
102
|
+
data << more
|
|
103
|
+
end
|
|
104
|
+
@error ? nil : data
|
|
105
|
+
end
|
|
106
|
+
|
|
92
107
|
def read_raw(length)
|
|
93
108
|
return nil if @eof
|
|
94
109
|
|
|
@@ -192,6 +207,8 @@ module GpxKit
|
|
|
192
207
|
# there is no more input, and anything unfinished is left for the XML
|
|
193
208
|
# parser to report.
|
|
194
209
|
def scan(buffer, complete:)
|
|
210
|
+
return :more if !complete && encoding_start?(buffer)
|
|
211
|
+
|
|
195
212
|
utf16 = utf16(buffer)
|
|
196
213
|
return scan(utf16, complete: complete) if utf16
|
|
197
214
|
|
|
@@ -219,6 +236,17 @@ module GpxKit
|
|
|
219
236
|
UTF16_LE_BOM = "\xFF\xFE".b.freeze
|
|
220
237
|
UTF16_BE_BOM = "\xFE\xFF".b.freeze
|
|
221
238
|
UTF32_LE_BOM = "\xFF\xFE\x00\x00".b.freeze
|
|
239
|
+
# How a document can start, decided by its first bytes: a byte order
|
|
240
|
+
# mark, or "<" in UTF-16 big-endian. ("<" alone, which may begin
|
|
241
|
+
# UTF-16 little-endian, is handled as unfinished markup.)
|
|
242
|
+
ENCODING_STARTS = [Source::BOM, UTF16_LE_BOM, UTF16_BE_BOM, UTF32_LE_BOM, "\x00<".b].freeze
|
|
243
|
+
|
|
244
|
+
# True when buffer is only the start of one of ENCODING_STARTS, so an
|
|
245
|
+
# input that hands over a few bytes at a time is read further before
|
|
246
|
+
# deciding what it is.
|
|
247
|
+
def encoding_start?(buffer)
|
|
248
|
+
ENCODING_STARTS.any? { |start| start.bytesize > buffer.bytesize && start.start_with?(buffer) }
|
|
249
|
+
end
|
|
222
250
|
|
|
223
251
|
# A UTF-8 copy of a UTF-16 buffer (by its byte order mark, or by "<"
|
|
224
252
|
# followed or preceded by a zero byte), so a DTD in a UTF-16 document
|