zsv 1.4.4-aarch64-linux-gnu
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 +7 -0
- data/CHANGELOG.md +187 -0
- data/LICENSE +21 -0
- data/README.md +203 -0
- data/ext/zsv/ZSV_UPSTREAM +7 -0
- data/ext/zsv/common.h +22 -0
- data/ext/zsv/extconf.rb +102 -0
- data/ext/zsv/options.c +126 -0
- data/ext/zsv/options.h +28 -0
- data/ext/zsv/options_internal.h +8 -0
- data/ext/zsv/parser.c +503 -0
- data/ext/zsv/parser.h +75 -0
- data/ext/zsv/row.c +169 -0
- data/ext/zsv/row.h +45 -0
- data/ext/zsv/upstream.rb +55 -0
- data/ext/zsv/vendor/zsv/LICENSE +21 -0
- data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
- data/ext/zsv/vendor/zsv/configure +1212 -0
- data/ext/zsv/vendor/zsv/include/zsv/api.h +375 -0
- data/ext/zsv/vendor/zsv/include/zsv/common.h +397 -0
- data/ext/zsv/vendor/zsv/include/zsv/ext/implementation.h +62 -0
- data/ext/zsv/vendor/zsv/include/zsv/ext/implementation_private.h +113 -0
- data/ext/zsv/vendor/zsv/include/zsv/ext/sheet.h +80 -0
- data/ext/zsv/vendor/zsv/include/zsv/ext.h +333 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/arg.h +139 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/cache.h +49 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/clock.h +36 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/compiler.h +69 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/db.h +19 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/dirs.h +149 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/dl.h +22 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/emcc/fs_api.h +28 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/err.h +22 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/file-mem.h +18 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/file.h +125 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/jq.h +65 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/json.h +19 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/mem.h +19 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/memmem.h +13 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite.h +71 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite_writer.h +53 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/prop.h +119 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/signal.h +25 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/string.h +173 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/utf8.h +41 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/win/dl.h +25 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/writer.h +109 -0
- data/ext/zsv/vendor/zsv/include/zsv/zsv_export.h +33 -0
- data/ext/zsv/vendor/zsv/include/zsv.h.in +18 -0
- data/ext/zsv/vendor/zsv/src/Makefile +238 -0
- data/ext/zsv/vendor/zsv/src/vector_delim.c +60 -0
- data/ext/zsv/vendor/zsv/src/zsv.c +622 -0
- data/ext/zsv/vendor/zsv/src/zsv_internal.c +789 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_delim.c +285 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_fixed.c +88 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
- data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
- data/ext/zsv/zsv_ext.c +417 -0
- data/lib/zsv/3.3/zsv.so +0 -0
- data/lib/zsv/3.4/zsv.so +0 -0
- data/lib/zsv/4.0/zsv.so +0 -0
- data/lib/zsv/errors.rb +32 -0
- data/lib/zsv/input.rb +88 -0
- data/lib/zsv/options.rb +132 -0
- data/lib/zsv/strict_validator.rb +124 -0
- data/lib/zsv/version.rb +5 -0
- data/lib/zsv.rb +183 -0
- metadata +196 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7d127dcdf15eb3cf2e24f14d72137d400f010846b46e96ebda072efa4252653e
|
|
4
|
+
data.tar.gz: 606edb0121018f312cd031b014687883a8c7369e5845bacbd1f041464e34472a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 357206e45641097abd44ea3631c7d20653820991f25da0f1312a899e1cdcad27cb94059ac8554cf417c38b4984f3029b6bd5d18eb62f635035788f48a0a955e7
|
|
7
|
+
data.tar.gz: 6e9f3d01a40afca30c118a4646ecbd755299454ba0987640205611c83ae8a618aae63f601cbc483b2239fb55359c7fdd1fb364fa663ef1a15b84ae867ccbb6bd
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
|
|
7
|
+
Versioning: gem `X.Y.Z` ships the zsv C library `X.Y.Z` (a gem-only release
|
|
8
|
+
adds a fourth segment, `X.Y.Z.N`), so the version number follows zsv, not
|
|
9
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). A release can
|
|
10
|
+
therefore change behaviour without a major bump: every such change is listed
|
|
11
|
+
under **Changed — breaking**, with what to do before upgrading.
|
|
12
|
+
|
|
13
|
+
## [Unreleased]
|
|
14
|
+
|
|
15
|
+
## [1.4.4] - 2026-11-23
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- IO sources: `ZSV::Parser.new(io)`, `ZSV.parse_enum(io)` read any object
|
|
19
|
+
responding to `#read` (File, StringIO, pipes, sockets) as the rows are
|
|
20
|
+
consumed. Fields carry the IO's external encoding.
|
|
21
|
+
- `ZSV.parse_line(line, **options)`, like `CSV.parse_line`.
|
|
22
|
+
- `ZSV::Parser.from_string(csv, **options)` and
|
|
23
|
+
`ZSV::Parser.from_path(path, **options)`: build a parser without the
|
|
24
|
+
String-is-data-or-path guess of `ZSV::Parser.new`.
|
|
25
|
+
- `headers:` accepts a String (the header names as one CSV line) and
|
|
26
|
+
`:first_row` (same as `true`), as in `CSV`.
|
|
27
|
+
- `ZSV.open` and `ZSV.foreach` accept a read mode: `"r"`, `"rb"`, `"rt"`, and
|
|
28
|
+
`"r:<encoding>"` (`"r:bom|utf-8"`, `"r:iso-8859-1"`). Write modes raise
|
|
29
|
+
`ArgumentError`.
|
|
30
|
+
- Strict mode: `liberal_parsing: false` validates the input like `CSV` does
|
|
31
|
+
and raises `ZSV::MalformedCSVError` (quoting errors) or
|
|
32
|
+
`ZSV::InvalidEncodingError` (bytes invalid in the source encoding), both
|
|
33
|
+
with `#line_number` (alias `#lineno`). It reads the whole input before the
|
|
34
|
+
first row and is slower than the default lenient mode.
|
|
35
|
+
- `max_row_size` (default 262144 bytes) and `max_columns` (default 1024)
|
|
36
|
+
options: the limits past which a row raises instead of being cut.
|
|
37
|
+
- Precompiled gems for x86_64 and aarch64 Linux (glibc and musl) and x86_64
|
|
38
|
+
and arm64 macOS, published with each release: no C compiler needed there.
|
|
39
|
+
- Offline install: the zsv source ships inside the gem, pinned by SHA-256
|
|
40
|
+
(see Security / Packaging). `gem install` never touches the network.
|
|
41
|
+
|
|
42
|
+
### Changed — breaking, read before upgrading
|
|
43
|
+
- **Unknown options raise `ArgumentError`** (`unknown keyword: :converters`).
|
|
44
|
+
They were silently ignored before. Upgrade: remove options ZSV does not
|
|
45
|
+
implement (`converters`, `strip`, `skip_blanks`, `nil_value`, ...; the
|
|
46
|
+
list is in `docs/API_REFERENCE.md`) and do that work on the rows.
|
|
47
|
+
- **`quote_char` other than `'"'` and `row_sep` other than `:auto`, `"\n"`,
|
|
48
|
+
`"\r\n"` or `"\r"` raise `ArgumentError`.** They were accepted and had no
|
|
49
|
+
effect. Upgrade: drop them; zsv only quotes with `"` and auto-detects the
|
|
50
|
+
three line endings.
|
|
51
|
+
- **`liberal_parsing: false` now validates**: it is slower and raises on
|
|
52
|
+
malformed quoting or invalid encoding, where it used to be ignored (rows
|
|
53
|
+
were always parsed leniently). Upgrade: omit the option, or pass
|
|
54
|
+
`liberal_parsing: true`, to keep the old lenient behaviour and speed.
|
|
55
|
+
- **Field encoding follows the source**: the String's encoding for
|
|
56
|
+
`ZSV.parse`, the IO's external encoding for IOs, `encoding:` or the mode's
|
|
57
|
+
encoding for files (UTF-8 when none is given). Fields were always tagged
|
|
58
|
+
UTF-8 before, so a binary String (`File.binread`, `"..".b`) now yields
|
|
59
|
+
BINARY (ASCII-8BIT) fields. Upgrade: `force_encoding('UTF-8')` the input,
|
|
60
|
+
or pass `encoding: 'UTF-8'`.
|
|
61
|
+
- **A blank line is an empty row `[]`, as in `CSV`**: `ZSV.parse("a\n\nb\n")`
|
|
62
|
+
is `[["a"], [], ["b"]]`, was `[["a"], [""], ["b"]]`. With headers it is a
|
|
63
|
+
Hash with every header mapped to `nil` (was `{first_header => ""}`); blank
|
|
64
|
+
lines before the header row are skipped. A line holding only `""` is now
|
|
65
|
+
`[""]` (it was dropped). Upgrade: `reject(&:empty?)` if you counted on
|
|
66
|
+
non-empty rows.
|
|
67
|
+
- **Header rows match `CSV`**: a row shorter than the headers has `nil` for
|
|
68
|
+
the missing fields (the keys were absent), and when a header name repeats
|
|
69
|
+
its first column wins (the last one did). Upgrade: `row.compact` for the
|
|
70
|
+
old missing-key shape; rename duplicate headers to read every column.
|
|
71
|
+
- **How `ZSV::Parser.new` reads its argument**: a `Pathname` or other
|
|
72
|
+
`#to_path` object that is not an open stream is a path (it was read as an
|
|
73
|
+
IO and looped forever); a String holding a line ending or a NUL byte, or
|
|
74
|
+
empty, is data; otherwise an existing file of that name is a path (a file
|
|
75
|
+
with a comma in its name is found); otherwise a String containing
|
|
76
|
+
`col_sep` is data (`"a,b"`, `"a;b"` with `col_sep: ";"`); anything else is
|
|
77
|
+
a missing path (`Errno::ENOENT`). Upgrade: use `ZSV::Parser.from_string` or
|
|
78
|
+
`from_path` (or `ZSV.parse` / `ZSV.open`) to choose explicitly.
|
|
79
|
+
- **`skip_lines` must be a non-negative Integer**; a Regexp, a String or a
|
|
80
|
+
negative number raises `ArgumentError` (a negative value was ignored).
|
|
81
|
+
Upgrade: skip matching rows yourself (`each.reject { ... }`).
|
|
82
|
+
- **Over-long and over-wide rows raise `ZSV::MalformedCSVError`** instead of
|
|
83
|
+
being returned cut short: a row longer than `max_row_size` (default
|
|
84
|
+
256 KiB, the old buffer size) and a row with more than `max_columns`
|
|
85
|
+
(default 1024) fields, whose extra fields were dropped. Upgrade: pass a
|
|
86
|
+
larger `max_row_size:` / `max_columns:` for such files.
|
|
87
|
+
- **A source build targets the baseline CPU** (SSE2 on x86_64, NEON on
|
|
88
|
+
aarch64; zsv's SIMD scanner stays on) instead of the build machine's
|
|
89
|
+
(`-march=native`, AVX2). A binary built in a Docker image on one CPU used
|
|
90
|
+
to die with SIGILL on another. Upgrade: nothing to do; to build for the
|
|
91
|
+
local CPU when the code only runs where it was built,
|
|
92
|
+
`gem install zsv --platform ruby -- --enable-native` (or `ZSV_NATIVE=1`).
|
|
93
|
+
On the bundled benchmarks the portable and native builds were within run-to-run noise of each other (x86_64, Ruby 4.0); the Benchmarks workflow reports current numbers.
|
|
94
|
+
|
|
95
|
+
### Changed
|
|
96
|
+
- Upgraded the bundled zsv C library from 1.4.3 to 1.4.4. Parser-library
|
|
97
|
+
changes are small: malformed-UTF-8 replacement now works on targets where
|
|
98
|
+
`char` is unsigned (e.g. gcc on ARM Linux), plus a new optional per-cell
|
|
99
|
+
malformed-UTF-8 handler this gem does not use yet. Most of the release is the
|
|
100
|
+
zsv CLI. See the
|
|
101
|
+
[zsv 1.4.4 release notes](https://github.com/liquidaty/zsv/releases/tag/v1.4.4).
|
|
102
|
+
|
|
103
|
+
### Fixed
|
|
104
|
+
- `ZSV.parse` could abort the whole Ruby process (`[BUG] Aborted`).
|
|
105
|
+
- A row longer than the read buffer (256 KiB by default) was returned cut
|
|
106
|
+
short and the rest of it dropped, with no error. A row of up to
|
|
107
|
+
`max_row_size` bytes now always parses completely, whatever `buffer_size`
|
|
108
|
+
is, and a longer row raises `ZSV::MalformedCSVError` with its line number
|
|
109
|
+
(`#line_number`).
|
|
110
|
+
- A row with more than 1024 fields lost the extra fields silently. It now
|
|
111
|
+
raises `ZSV::MalformedCSVError`; `max_columns` raises the limit.
|
|
112
|
+
- `ZSV::Parser#initialize` given a `Pathname` read it as an IO, and
|
|
113
|
+
`Pathname#read(n)` returns the first bytes of the file on every call, so the
|
|
114
|
+
rows repeated forever. A path-like object (`#to_path`, not an open stream) is
|
|
115
|
+
now opened as a path; a `File` is still read from its current position.
|
|
116
|
+
- `ZSV::Parser#each` and `#each_row` returned `nil` with a block; they return
|
|
117
|
+
the parser, like `CSV#each`.
|
|
118
|
+
- Calling `#initialize` again on a parser leaked the first parser's state; it
|
|
119
|
+
now raises `RuntimeError` and leaks nothing.
|
|
120
|
+
- Ruby code run from zsv's callbacks (an IO's `#read`, building rows) could
|
|
121
|
+
raise through zsv's C frames. It now runs under `rb_protect` and the
|
|
122
|
+
exception is re-raised once zsv has returned and the parser is released.
|
|
123
|
+
- The parser now supports GC compaction (its stored objects are marked
|
|
124
|
+
movable and updated), never calls into Ruby while being freed, calls
|
|
125
|
+
`zsv_finish` exactly once at end of input (never from `close` or free) and
|
|
126
|
+
checks its status, and leaks no `FILE *`, zsv parser or memory when options,
|
|
127
|
+
`#read`, the block or a second `#initialize` raise.
|
|
128
|
+
- A parser is no longer re-entered from its own callback or another thread:
|
|
129
|
+
that raises `ZSV::Error` instead of corrupting zsv's state.
|
|
130
|
+
- zsv's warnings no longer print to stderr.
|
|
131
|
+
|
|
132
|
+
### Security / Packaging
|
|
133
|
+
- `gem install` no longer downloads anything. The zsv source is vendored in the
|
|
134
|
+
gem (`ext/zsv/vendor/zsv`, with zsv's MIT `LICENSE`) and pinned by SHA-256 in
|
|
135
|
+
`ext/zsv/ZSV_UPSTREAM`. Before, `extconf.rb` fetched an unverified tarball
|
|
136
|
+
from GitHub at install time, and retried with TLS verification switched off
|
|
137
|
+
when verification failed.
|
|
138
|
+
- Precompiled platform gems are cross-built with `rake gem:native`
|
|
139
|
+
(rake-compiler-dock) for the baseline CPU of each architecture.
|
|
140
|
+
|
|
141
|
+
### Tooling
|
|
142
|
+
- `rake zsv:vendor`, `rake zsv:verify` and `rake "zsv:bump[X.Y.Z]"` manage the
|
|
143
|
+
vendored zsv. `bin/zsv-upstream-check` reports whether a newer zsv release
|
|
144
|
+
exists (exit 10 when one does).
|
|
145
|
+
|
|
146
|
+
## [1.4.3] - 2026-06-26
|
|
147
|
+
|
|
148
|
+
### Changed
|
|
149
|
+
- Upgraded the vendored zsv C library from 1.3.0 to 1.4.3, which introduces
|
|
150
|
+
zsv "fast mode" and assorted parser improvements and fixes. See the
|
|
151
|
+
[zsv 1.4.0 release notes](https://github.com/liquidaty/zsv/releases/tag/v1.4.0).
|
|
152
|
+
- Gem version bumped to 1.4.3 to stay in sync with the bundled zsv library.
|
|
153
|
+
|
|
154
|
+
### CI / Tooling
|
|
155
|
+
- CI now tests against Ruby 3.3, 3.4, and 4.0.
|
|
156
|
+
- Added a tag-driven release workflow that publishes to RubyGems via trusted
|
|
157
|
+
publishing (OIDC) and creates a GitHub Release (`rake release:tag`).
|
|
158
|
+
|
|
159
|
+
## [1.3.0] - 2025-12-08
|
|
160
|
+
|
|
161
|
+
### Added
|
|
162
|
+
- Initial release of zsv-ruby gem
|
|
163
|
+
- Core parsing functionality (foreach, parse, read, open)
|
|
164
|
+
- Header mode support (boolean and custom headers)
|
|
165
|
+
- Custom delimiter support (col_sep, quote_char)
|
|
166
|
+
- Parser class with shift, each, rewind, close methods
|
|
167
|
+
- Memory-efficient streaming parser
|
|
168
|
+
- Native C extension compiling against zsv 1.3.0
|
|
169
|
+
- SIMD optimizations via zsv library
|
|
170
|
+
- Comprehensive RSpec test suite
|
|
171
|
+
- Performance benchmarks
|
|
172
|
+
- Full API documentation
|
|
173
|
+
|
|
174
|
+
### Features
|
|
175
|
+
- Drop-in replacement for Ruby CSV stdlib
|
|
176
|
+
- 10-50x performance improvement on large files
|
|
177
|
+
- 90% memory usage reduction through streaming
|
|
178
|
+
- Support for Ruby 3.3+
|
|
179
|
+
- Proper encoding handling (UTF-8 default)
|
|
180
|
+
- Exception classes for error handling
|
|
181
|
+
|
|
182
|
+
### Architecture
|
|
183
|
+
- SOLID design with separated concerns
|
|
184
|
+
- Row builder for efficient array/hash conversion
|
|
185
|
+
- Options parser with validation
|
|
186
|
+
- Parser wrapper around zsv C library
|
|
187
|
+
- Proper GC integration and resource cleanup
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ZSV Ruby Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# zsv
|
|
2
|
+
|
|
3
|
+
[](https://github.com/sebyx07/zsv-ruby/actions/workflows/ci.yml)
|
|
4
|
+
[](https://rubygems.org/gems/zsv)
|
|
5
|
+
[](https://rubygems.org/gems/zsv)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://developerz.ai)
|
|
8
|
+
|
|
9
|
+
A fast CSV parser for Ruby with the reading API of the `CSV` standard library. The parsing is done by [zsv](https://github.com/liquidaty/zsv), a SIMD-accelerated C library, through a native extension.
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
require 'zsv'
|
|
13
|
+
|
|
14
|
+
ZSV.foreach('data.csv', headers: true) do |row|
|
|
15
|
+
puts row['name']
|
|
16
|
+
end
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **Familiar**: `ZSV.foreach`, `ZSV.parse`, `ZSV.read`, `ZSV.open`, `ZSV::Parser#shift` / `#each`, with the option names `CSV` uses.
|
|
20
|
+
- **Streaming**: rows are produced as the input is read; a file is never loaded whole.
|
|
21
|
+
- **Checked against `CSV`**: the test suite compares rows with the standard library's for the same input and option. The [intended differences](#differences-from-csv) are few and listed.
|
|
22
|
+
- **Self-contained**: the zsv source ships inside the gem, pinned by SHA-256. Installing downloads nothing beyond the gem and needs no system library.
|
|
23
|
+
|
|
24
|
+
It parses; it does not write CSV. For generating CSV, converters, or `CSV::Table`, keep using `csv`.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
# Gemfile
|
|
30
|
+
gem 'zsv'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or `gem install zsv`.
|
|
34
|
+
|
|
35
|
+
- **Precompiled gems** are published, from 1.4.4 on, for Linux (x86_64 and aarch64, glibc and musl) and macOS (x86_64 and arm64): no compiler needed. They are built for the baseline CPU of each architecture (SSE2 / NEON).
|
|
36
|
+
- **Everywhere else** the source gem compiles on install. That needs a C compiler and `make`, and nothing from the network: the zsv C source is inside the gem. A source build also targets the baseline CPU (SSE2 / NEON), so a binary built on one machine (a Docker image built in CI, for example) runs on any other machine of the same architecture. When the code runs only where it was built, you can build for that machine's CPU instead (`-march=native`):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
gem install zsv --platform ruby -- --enable-native
|
|
40
|
+
# or ZSV_NATIVE=1 gem install zsv --platform ruby; with Bundler:
|
|
41
|
+
bundle config set --local build.zsv --enable-native
|
|
42
|
+
bundle config set --local force_ruby_platform true
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Supported Rubies and platforms are the ones CI tests: see the matrix in [`.github/workflows/ci.yml`](.github/workflows/ci.yml). The Ruby floor is `required_ruby_version` in [`zsv.gemspec`](zsv.gemspec). Windows is not supported yet.
|
|
46
|
+
|
|
47
|
+
**Versioning.** The gem version is the version of the zsv library it wraps: gem `1.4.4` ships zsv `1.4.4`. A gem-only release adds a fourth segment (`1.4.4.1`).
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### Files
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
# Stream rows; nothing is kept
|
|
55
|
+
ZSV.foreach('data.csv') { |row| p row } # row is an Array of Strings
|
|
56
|
+
|
|
57
|
+
# Without a block: an Enumerator
|
|
58
|
+
ZSV.foreach('data.csv').with_index { |row, i| ... }
|
|
59
|
+
ZSV.foreach('data.csv').lazy.select { |row| row[2] == 'paid' }.first(10)
|
|
60
|
+
|
|
61
|
+
# Everything at once
|
|
62
|
+
rows = ZSV.read('data.csv') # => [["a", "b"], ["1", "2"]]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Strings
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
ZSV.parse("a,b\n1,2\n") # => [["a", "b"], ["1", "2"]]
|
|
69
|
+
ZSV.parse_line('a,"b,c"') # => ["a", "b,c"]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Headers
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
ZSV.parse("name,age\nAda,36\n", headers: true)
|
|
76
|
+
# => [{"name" => "Ada", "age" => "36"}]
|
|
77
|
+
|
|
78
|
+
# Supply the headers yourself (the first row is then data)
|
|
79
|
+
ZSV.foreach('data.csv', headers: %w[id name email]) { |row| row['email'] }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
With headers each row is a plain `Hash`, not a `CSV::Row`.
|
|
83
|
+
|
|
84
|
+
### A parser object
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
ZSV.open('data.csv', headers: true) do |csv| # closed when the block returns
|
|
88
|
+
first = csv.shift # one row, or nil at the end
|
|
89
|
+
csv.headers # => ["name", "age"] (nil until the first row is read)
|
|
90
|
+
csv.each { |row| ... } # the rest
|
|
91
|
+
csv.rewind
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
parser = ZSV::Parser.new(io) # any object with #read; or a path, a Pathname, CSV data
|
|
95
|
+
parser.each_slice(1_000) { |batch| ... } # Enumerable
|
|
96
|
+
parser.close
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`ZSV::Parser.new` guesses whether a String is CSV data or a path (see the [API reference](docs/API_REFERENCE.md)); `ZSV::Parser.from_string` and `ZSV::Parser.from_path` do not guess.
|
|
100
|
+
|
|
101
|
+
### Options
|
|
102
|
+
|
|
103
|
+
The common ones; the complete list, with defaults and every accepted value, is in [`docs/API_REFERENCE.md`](docs/API_REFERENCE.md).
|
|
104
|
+
|
|
105
|
+
| Option | Meaning |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `headers` | `true`: the first row names the fields. An `Array` or a CSV line: your own names |
|
|
108
|
+
| `col_sep` | Column separator, one ASCII character (`"\t"`, `";"`, `"|"`) |
|
|
109
|
+
| `skip_lines` | Number of leading rows to drop |
|
|
110
|
+
| `liberal_parsing` | `false`: raise `ZSV::MalformedCSVError` on malformed input, as `CSV` does by default |
|
|
111
|
+
| `encoding` | Encoding the returned Strings are labelled with (no transcoding) |
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
ZSV.foreach('data.tsv', col_sep: "\t", headers: true) { |row| ... }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
An option the gem does not implement raises `ArgumentError`; nothing is silently ignored.
|
|
118
|
+
|
|
119
|
+
### Errors
|
|
120
|
+
|
|
121
|
+
`ZSV::Error` is the base class. `ZSV::MalformedCSVError` and `ZSV::InvalidEncodingError` mirror `CSV`'s. A missing file raises the usual `Errno::ENOENT`.
|
|
122
|
+
|
|
123
|
+
## Differences from `CSV`
|
|
124
|
+
|
|
125
|
+
The suite compares ZSV's rows with `CSV`'s for the same input. These differences are intended:
|
|
126
|
+
|
|
127
|
+
| | `CSV` | `ZSV` |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| Malformed input | raises by default (`liberal_parsing: false`) | **lenient by default**: zsv never rejects input. Pass `liberal_parsing: false` to validate like `CSV` and raise `ZSV::MalformedCSVError` |
|
|
130
|
+
| Empty unquoted field (`a,,b`) | `nil` | `""` |
|
|
131
|
+
| Row with headers | `CSV::Row`; `CSV.parse` returns a `CSV::Table` | a plain `Hash`; `ZSV.parse` returns an `Array` of them. With duplicate header names the first one wins, as in `CSV::Row#to_h` |
|
|
132
|
+
| Field Strings | mutable | frozen |
|
|
133
|
+
| UTF-8 BOM | kept unless `encoding: 'bom|utf-8'` | always stripped |
|
|
134
|
+
| `col_sep` | any String | one ASCII character |
|
|
135
|
+
| `quote_char` | any character | only `"` |
|
|
136
|
+
| `row_sep` | any String | always auto-detected (`\n`, `\r\n`, `\r`) |
|
|
137
|
+
| `skip_lines` | a pattern matching lines to skip | a number of leading rows to drop |
|
|
138
|
+
| `encoding` | can transcode (`'iso-8859-1:utf-8'`) | labels the returned Strings; no transcoding |
|
|
139
|
+
| Very wide rows | no limit | more than `max_columns` fields (1024 unless raised) raises `ZSV::MalformedCSVError` rather than dropping data |
|
|
140
|
+
| Very long rows | no limit | a row over `max_row_size` bytes (256 KiB unless raised) raises `ZSV::MalformedCSVError` rather than being cut short |
|
|
141
|
+
| Converters, `CSV::Table`, writing | yes | no: unsupported options raise `ArgumentError` |
|
|
142
|
+
|
|
143
|
+
[`docs/API_REFERENCE.md`](docs/API_REFERENCE.md) is the authoritative list.
|
|
144
|
+
|
|
145
|
+
## Performance
|
|
146
|
+
|
|
147
|
+
zsv scans input with SIMD instructions and the extension builds Ruby rows directly in C, so parsing is faster than the pure-Ruby `CSV`. How much depends on the shape of the data (row width, quoting), the options (rows as Hashes cost more than rows as Arrays), the CPU and the Ruby version, so this README does not carry a headline number.
|
|
148
|
+
|
|
149
|
+
**Current numbers are produced by CI**: the [Benchmarks workflow](https://github.com/sebyx07/zsv-ruby/actions/workflows/benchmark.yml) runs on every push to `main`, on x86_64 and arm64 Linux, and prints the full output in each run's summary, with the Ruby version and commit.
|
|
150
|
+
|
|
151
|
+
As a guide, across the maintainers' runs of `bundle exec rake bench` on x86_64 Linux, `ZSV.foreach` has typically been 3 to 4 times faster than `CSV.foreach`: a little over 2x on very wide rows, up to about 11 to 12x on heavily quoted data. `liberal_parsing: false` adds a validation pass in Ruby and lands near 2x. ZSV makes about half the allocations and holds a parsed file in noticeably less memory. These are ranges from a few machines, not a promise: the CI summaries and your own run are the reference.
|
|
152
|
+
|
|
153
|
+
Reproduce it on your own data and hardware:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
git clone https://github.com/sebyx07/zsv-ruby && cd zsv-ruby
|
|
157
|
+
bin/setup
|
|
158
|
+
bundle exec rake bench # benchmark/parse_bench.rb and benchmark/memory_bench.rb
|
|
159
|
+
BENCH_TIME=10 BENCH_JSON=parse.json bundle exec ruby benchmark/parse_bench.rb # longer runs, JSON in benchmark/results/
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Both sides of every comparison do the same work on the same generated, fixed-seed input, and the scripts abort if the two parsers disagree on the rows.
|
|
163
|
+
|
|
164
|
+
## Documentation
|
|
165
|
+
|
|
166
|
+
- [Quick start](docs/QUICKSTART.md)
|
|
167
|
+
- [API reference](docs/API_REFERENCE.md): every method, option, error and difference from `CSV`
|
|
168
|
+
- [`llms.txt`](llms.txt): the same reference condensed into one file for AI coding agents
|
|
169
|
+
- [Changelog](CHANGELOG.md)
|
|
170
|
+
|
|
171
|
+
## AI agents
|
|
172
|
+
|
|
173
|
+
**This project is maintained by [developerz.ai](https://developerz.ai).** Its maintainer agent triages issues, reviews every pull request, merges every pull request once its author marks it ready and CI passes, watches project health daily, follows new releases of the zsv C library, and opens release PRs. The policy is in [`.dz/maintainer/maintainer.yml`](.dz/maintainer/maintainer.yml). Breaking changes stay with the owner.
|
|
174
|
+
|
|
175
|
+
- **Using zsv in your app?** Point your agent at [`llms.txt`](llms.txt), the complete reference in one file (methods, options, differences from `CSV`, pitfalls). Paste this into your app's `CLAUDE.md` / `AGENTS.md`:
|
|
176
|
+
```markdown
|
|
177
|
+
## CSV parsing
|
|
178
|
+
CSV files are read with the zsv gem (`ZSV.foreach`, `ZSV.parse`), not Ruby's CSV. Before editing that code read
|
|
179
|
+
https://github.com/sebyx07/zsv-ruby/blob/main/llms.txt
|
|
180
|
+
```
|
|
181
|
+
- **Working on this repo?** [`CLAUDE.md`](CLAUDE.md) is the agent-instructions file (`AGENTS.md` is a symlink to it): invariants, commands, code map, how to verify a change, the release lane. [`ext/CLAUDE.md`](ext/CLAUDE.md) holds the rules for the C extension.
|
|
182
|
+
- **Claude Code**: commands in `.claude/commands/` (`/planx`, `/feature`, `/release`), skills in `.claude/skills/` (`verify-change`, `upgrade-zsv`, `debug-gc`), and a read-only reviewer subagent in `.claude/agents/` (`c-safety-reviewer`).
|
|
183
|
+
- **How the gem follows zsv**: once a month an agent runs `bin/zsv-upstream-check`; when zsv has a new release it reads the upstream changes, re-vendors the source, runs the suite, the sanitizers and the benchmarks before and after, and opens `chore: zsv X.Y.Z`. The next weekly release check then publishes gem `X.Y.Z`. The brief is [`.dz/schedules/upstream-zsv.md`](.dz/schedules/upstream-zsv.md).
|
|
184
|
+
|
|
185
|
+
## Development
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
bin/setup # Ruby, gems, compile the extension (offline after the gems)
|
|
189
|
+
bin/check # the gate CI runs: repo guards, RuboCop, clang-format, compile, RSpec
|
|
190
|
+
bin/check fast # inner loop
|
|
191
|
+
bin/check asan # the suite under AddressSanitizer + UBSan (Linux)
|
|
192
|
+
bin/console # IRB with ZSV and CSV loaded
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Security reports go through [SECURITY.md](SECURITY.md) (GitHub private vulnerability reporting), never a public issue. Releases are cut by merging a version bump: [RELEASE.md](RELEASE.md).
|
|
196
|
+
|
|
197
|
+
## License and credits
|
|
198
|
+
|
|
199
|
+
MIT, see [LICENSE](LICENSE). The bundled [zsv](https://github.com/liquidaty/zsv) library is by Liquidaty and also MIT-licensed; its license ships with the gem at `ext/zsv/vendor/zsv/LICENSE`.
|
|
200
|
+
|
|
201
|
+
## Star history
|
|
202
|
+
|
|
203
|
+
[](https://star-history.com/#sebyx07/zsv-ruby&Date)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# The zsv C library release this gem is built from (gem X.Y.Z wraps zsv X.Y.Z).
|
|
2
|
+
# Read by ext/zsv/upstream.rb (Rakefile, extconf.rb) and bin/zsv-upstream-check.
|
|
3
|
+
#
|
|
4
|
+
# To upgrade: `bundle exec rake "zsv:bump[NEW_VERSION]"`, which rewrites this
|
|
5
|
+
# file with the new tarball's SHA-256 and re-vendors ext/zsv/vendor/zsv.
|
|
6
|
+
version=1.4.4
|
|
7
|
+
sha256=99486b6901d6b576bf15afceb0bcc888ceeb3f555a6d489547eefe67eff52079
|
data/ext/zsv/common.h
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* Common header for zsv Ruby extension */
|
|
2
|
+
#ifndef ZSV_RUBY_COMMON_H
|
|
3
|
+
#define ZSV_RUBY_COMMON_H
|
|
4
|
+
|
|
5
|
+
#include <ruby.h>
|
|
6
|
+
#include <ruby/encoding.h>
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
#include <zsv.h>
|
|
9
|
+
|
|
10
|
+
/* Module and class references */
|
|
11
|
+
extern VALUE mZSV;
|
|
12
|
+
extern VALUE cParser;
|
|
13
|
+
extern VALUE eZSVError;
|
|
14
|
+
extern VALUE eMalformedCSVError;
|
|
15
|
+
extern VALUE eInvalidEncodingError;
|
|
16
|
+
|
|
17
|
+
/* Memory management macros - use Ruby's built-in */
|
|
18
|
+
#define ZSV_ALLOC(type) RB_ALLOC(type)
|
|
19
|
+
#define ZSV_ALLOC_N(type, n) RB_ALLOC_N(type, n)
|
|
20
|
+
#define ZSV_REALLOC_N(var, type, n) RB_REALLOC_N(var, type, n)
|
|
21
|
+
|
|
22
|
+
#endif /* ZSV_RUBY_COMMON_H */
|
data/ext/zsv/extconf.rb
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mkmf'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'shellwords'
|
|
6
|
+
require_relative 'upstream'
|
|
7
|
+
|
|
8
|
+
# Builds the zsv C library from the source vendored in ext/zsv/vendor/zsv (see
|
|
9
|
+
# ZSV_UPSTREAM and `rake zsv:vendor`), then links it statically into the
|
|
10
|
+
# extension. No network access happens here.
|
|
11
|
+
#
|
|
12
|
+
# The default build targets the baseline CPU of the architecture (SSE2 on
|
|
13
|
+
# x86_64, NEON on aarch64), so a binary built on one machine (a Docker image
|
|
14
|
+
# built in CI, say) runs on any other machine of that architecture instead of
|
|
15
|
+
# dying with SIGILL.
|
|
16
|
+
#
|
|
17
|
+
# Options (`gem install zsv -- --enable-native`, or ZSV_NATIVE=1):
|
|
18
|
+
# --enable-native build for the build machine's CPU (-march=native,
|
|
19
|
+
# AVX2 when it has it). Only for binaries that run
|
|
20
|
+
# where they were built.
|
|
21
|
+
# --enable-cross-build set by the Rakefile for rake-compiler-dock builds of
|
|
22
|
+
# precompiled gems; always baseline, ignores
|
|
23
|
+
# --enable-native.
|
|
24
|
+
|
|
25
|
+
def vendored_zsv_dir
|
|
26
|
+
unless ZSVUpstream.vendored_current?
|
|
27
|
+
abort <<~MSG
|
|
28
|
+
The zsv #{ZSVUpstream.version} C source is missing from #{ZSVUpstream::VENDOR_DIR}
|
|
29
|
+
(or was vendored from a different ZSV_UPSTREAM pin).
|
|
30
|
+
In a git checkout run `bundle exec rake zsv:vendor`; released gems always include it.
|
|
31
|
+
MSG
|
|
32
|
+
end
|
|
33
|
+
ZSVUpstream::VENDOR_DIR
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def cross_compiling?
|
|
37
|
+
enable_config('cross-build', false)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def native_build?
|
|
41
|
+
!cross_compiling? && enable_config('native', ENV['ZSV_NATIVE'] == '1')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def configure_args
|
|
45
|
+
# --minimal drops ZSV_EXTRAS (row limits, progress callbacks, sidecar
|
|
46
|
+
# overwrite files), which this gem does not use and which needs sqlite3.h
|
|
47
|
+
# from upstream's app/ tree, deliberately not vendored.
|
|
48
|
+
args = %w[--minimal=yes]
|
|
49
|
+
# SSE2 (x86_64) and NEON (aarch64) are part of the baseline ABI and still
|
|
50
|
+
# select zsv's SIMD scanner; only AVX/AVX2 and -march=native are dropped.
|
|
51
|
+
args += %w[--arch=none --force-avx2=no --force-avx=no] unless native_build?
|
|
52
|
+
args
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def build_env
|
|
56
|
+
env = { 'CC' => RbConfig::CONFIG['CC'], 'AR' => RbConfig::CONFIG['AR'] }
|
|
57
|
+
env['CROSS_COMPILING'] = 'yes' if cross_compiling?
|
|
58
|
+
env.compact
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def run!(env, *cmd)
|
|
62
|
+
puts "#{env.map { |k, v| "#{k}=#{v.shellescape}" }.join(' ')} #{cmd.shelljoin}"
|
|
63
|
+
system(env, *cmd) or abort("zsv build failed: #{cmd.shelljoin}")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Builds a private copy so the vendored tree stays pristine and builds for
|
|
67
|
+
# several Rubies or platforms never share a config.mk.
|
|
68
|
+
def build_zsv(source_dir, build_dir)
|
|
69
|
+
FileUtils.rm_rf(build_dir)
|
|
70
|
+
FileUtils.cp_r(source_dir, build_dir)
|
|
71
|
+
env = build_env
|
|
72
|
+
Dir.chdir(build_dir) do
|
|
73
|
+
run!(env, './configure', *configure_args)
|
|
74
|
+
run!(env, find_executable('gmake') || 'make', '-C', 'src', 'build', "VERSION=#{ZSVUpstream.version}")
|
|
75
|
+
end
|
|
76
|
+
Dir.glob(File.join(build_dir, 'build', '*', 'rel', '*', 'lib', 'libzsv.a')).first or
|
|
77
|
+
abort("libzsv.a not found under #{build_dir}/build")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
zsv_build_dir = File.join(Dir.pwd, 'zsv-build')
|
|
81
|
+
puts "Building zsv #{ZSVUpstream.version} (#{native_build? ? 'native CPU' : 'portable baseline CPU'})"
|
|
82
|
+
zsv_lib = build_zsv(vendored_zsv_dir, zsv_build_dir)
|
|
83
|
+
include_dir = File.join(zsv_build_dir, 'include')
|
|
84
|
+
|
|
85
|
+
$INCFLAGS << " -I#{include_dir}"
|
|
86
|
+
$CFLAGS << ' -std=c99 -Wall -Wextra'
|
|
87
|
+
$CFLAGS << ' -O3'
|
|
88
|
+
|
|
89
|
+
abort("zsv.h not found in #{include_dir}") unless have_header('zsv.h')
|
|
90
|
+
|
|
91
|
+
$LOCAL_LIBS << " #{zsv_lib}"
|
|
92
|
+
|
|
93
|
+
if RUBY_PLATFORM.include?('darwin')
|
|
94
|
+
$LDFLAGS << ' -framework Foundation'
|
|
95
|
+
elsif RUBY_PLATFORM.include?('linux')
|
|
96
|
+
$LIBS << ' -lpthread -lm'
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Ruby 3.2+ hash capacity preallocation
|
|
100
|
+
have_func('rb_hash_new_capa')
|
|
101
|
+
|
|
102
|
+
create_makefile('zsv/zsv')
|