zlight_csv 0.1.0-x64-mingw-ucrt

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb55a3e4c03461686afc347e9e4ff8bd6ba3388b3debc71564f94ebcef7f5cc5
4
+ data.tar.gz: b8f987137e9dfddb045c3a410883ded0f682a62a4f50f20b41db4f7225253748
5
+ SHA512:
6
+ metadata.gz: ffea9b304636f2855c17ff9694a77f8bcc2c0567a6b11944989d893de0ee2734d76d5bd8e279d1b9bb76820b85ed29052aab6aca6c8114a8dc3dfa3201bf8857
7
+ data.tar.gz: 660bbbd15c02833111151cdbe43cb1b37990cf43ecfe9757b4df4a14c069c2aad447f7d12bccfbe32e301442d84e337f567f325a924897867905a7bb0e595171
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
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
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2024-XX-XX
11
+
12
+ ### Added
13
+
14
+ - Initial release
15
+ - `Zlight::Csv.parse` - Parse CSV strings with optional headers and numeric conversion
16
+ - `Zlight::Csv.read` - Read and parse CSV files
17
+ - `Zlight::Csv.foreach` - Iterate over CSV rows
18
+ - `Zlight.parse` and `Zlight.read` convenience methods
19
+ - Support for custom delimiters (`col_sep`)
20
+ - Support for custom quote characters (`quote_char`)
21
+ - Flexible record length support
22
+ - Enum-based error handling with descriptive messages
23
+ - Cross-platform native gem builds
24
+
25
+ ### Performance
26
+
27
+ - Up to 10x faster than Ruby's standard CSV library
28
+ - Efficient memory usage through Rust's zero-copy parsing
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Zaidan Chaudhary
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,345 @@
1
+ # ZLight
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/zlight_csv.svg)](https://badge.fury.io/rb/zlight_csv)
4
+ [![CI](https://github.com/yourusername/zlight-csv/actions/workflows/ci.yml/badge.svg)](https://github.com/yourusername/zlight-csv/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ A blazing-fast CSV parser for Ruby, powered by Rust. ZLight provides a simple API for parsing CSV files **up to 30x faster** than Ruby's standard CSV library.
8
+
9
+ ## Features
10
+
11
+ - **High Performance**: Built with Rust's `csv` crate for maximum speed
12
+ - **Simple API**: Just `ZLight.parse(csv_string)`
13
+ - **Automatic Type Conversion**: Optional numeric conversion for integer and float fields
14
+ - **Symbol Headers**: Automatically converts headers to symbols
15
+ - **Cross-Platform**: Pre-built binaries for Linux, macOS, and Windows
16
+
17
+ ## Benchmarks
18
+
19
+ Parsing 100,000 rows with headers and numeric conversion:
20
+
21
+ ```
22
+ user system total real
23
+ Ruby StdLib CSV: 1.49s
24
+ ZLight (Rust): 0.05s
25
+ ```
26
+
27
+ **~30x faster** than Ruby's standard CSV library!
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'zlight_csv'
35
+ ```
36
+
37
+ Then execute:
38
+
39
+ ```bash
40
+ bundle install
41
+ ```
42
+
43
+ Or install it directly:
44
+
45
+ ```bash
46
+ gem install zlight_csv
47
+ ```
48
+
49
+ ### Prebuilt Binaries (No Rust Required)
50
+
51
+ ZLight ships **prebuilt native gems** for the following platforms:
52
+
53
+ | Platform | Architecture |
54
+ |----------|--------------|
55
+ | Linux | x86_64, aarch64 |
56
+ | Linux (musl/Alpine) | x86_64 |
57
+ | macOS | x86_64 (Intel), arm64 (Apple Silicon) |
58
+ | Windows | x64 (UCRT) |
59
+
60
+ When you run `gem install zlight_csv`, RubyGems automatically downloads the correct prebuilt binary for your platform. **No Rust toolchain required!**
61
+
62
+ ### Requirements
63
+
64
+ - Ruby >= 3.0.0 (3.0, 3.1, 3.2, 3.3)
65
+ - Supported platforms: Linux, macOS, Windows (see above)
66
+
67
+ ## Usage
68
+
69
+ ### Basic Parsing
70
+
71
+ ```ruby
72
+ require 'zlight_csv'
73
+
74
+ csv_data = <<~CSV
75
+ name,age,city
76
+ Alice,30,New York
77
+ Bob,25,London
78
+ Charlie,35,Paris
79
+ CSV
80
+
81
+ # Parse with headers (returns array of hashes with symbol keys)
82
+ result = ZLight.parse(csv_data, headers: true)
83
+ # => [{:name=>"Alice", :age=>"30", :city=>"New York"}, ...]
84
+
85
+ # headers: true is the default
86
+ result = ZLight.parse(csv_data)
87
+ ```
88
+
89
+ ### Numeric Conversion
90
+
91
+ ```ruby
92
+ # Automatically convert numeric strings to integers/floats
93
+ result = ZLight.parse(csv_data, headers: true, converters: :numeric)
94
+ # => [{:name=>"Alice", :age=>30, :city=>"New York"}, ...]
95
+ ```
96
+
97
+ ### Without Headers
98
+
99
+ ```ruby
100
+ csv_data = "Alice,30,New York\nBob,25,London"
101
+
102
+ result = ZLight.parse(csv_data, headers: false)
103
+ # => [["Alice", "30", "New York"], ["Bob", "25", "London"]]
104
+
105
+ # With numeric conversion
106
+ result = ZLight.parse(csv_data, headers: false, converters: :numeric)
107
+ # => [["Alice", 30, "New York"], ["Bob", 25, "London"]]
108
+ ```
109
+
110
+ ### Reading Files
111
+
112
+ ```ruby
113
+ # Read and parse a CSV file
114
+ result = ZLight.read("path/to/file.csv", headers: true, converters: :numeric)
115
+ ```
116
+
117
+ ### Iteration
118
+
119
+ ```ruby
120
+ # Iterate over rows
121
+ ZLight.foreach(csv_data, headers: true) do |row|
122
+ puts row[:name]
123
+ end
124
+
125
+ # With Enumerator
126
+ enum = ZLight.foreach(csv_data, headers: true)
127
+ enum.map { |row| row[:name].upcase }
128
+ ```
129
+
130
+ ### Custom Delimiters
131
+
132
+ ```ruby
133
+ # Tab-separated values
134
+ tsv_data = "name\tage\nAlice\t30"
135
+ result = ZLight.parse(tsv_data, headers: true, col_sep: "\t")
136
+
137
+ # Semicolon-separated (common in European locales)
138
+ result = ZLight.parse(data, headers: true, col_sep: ";")
139
+ ```
140
+
141
+ ### Options Reference
142
+
143
+ | Option | Type | Default | Description |
144
+ |--------|------|---------|-------------|
145
+ | `headers` | Boolean | `true` | Treat first row as headers |
146
+ | `converters` | Symbol | `nil` | Set to `:numeric` for auto-conversion |
147
+ | `col_sep` | String | `","` | Column separator character |
148
+ | `quote_char` | String | `"` | Quote character |
149
+ | `flexible` | Boolean | `true` | Allow variable length records |
150
+
151
+ ## Development
152
+
153
+ ### Prerequisites
154
+
155
+ 1. Docker (for cross-compilation)
156
+ 2. Rust toolchain (for local development)
157
+ ```bash
158
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
159
+ ```
160
+
161
+ ### Local Development
162
+
163
+ ```bash
164
+ # Clone the repository
165
+ git clone https://github.com/yourusername/zlight-csv.git
166
+ cd zlight-csv
167
+
168
+ # Install dependencies
169
+ bundle install
170
+
171
+ # Compile the native extension (requires Rust)
172
+ bundle exec rake compile
173
+
174
+ # Run tests
175
+ bundle exec rake spec
176
+
177
+ # Run benchmarks
178
+ bundle exec rake benchmark
179
+
180
+ # Clean build artifacts
181
+ bundle exec rake clean
182
+ ```
183
+
184
+ ## Publishing to RubyGems
185
+
186
+ ### Automated Release (Recommended)
187
+
188
+ Releases are fully automated via GitHub Actions. When you push a version tag:
189
+
190
+ 1. Builds prebuilt native gems for all 6 platforms
191
+ 2. Publishes all gems to RubyGems
192
+ 3. Creates a GitHub Release with all gem files attached
193
+
194
+ **To release:**
195
+
196
+ ```bash
197
+ # 1. Update version
198
+ vim lib/zlight_csv/version.rb
199
+
200
+ # 2. Update changelog
201
+ vim CHANGELOG.md
202
+
203
+ # 3. Commit and tag
204
+ git add -A
205
+ git commit -m "Release v0.1.0"
206
+ git tag v0.1.0
207
+ git push origin main --tags
208
+ ```
209
+
210
+ GitHub Actions handles the rest automatically.
211
+
212
+ ### RubyGems setup (one-time)
213
+
214
+ Publishing uses [Trusted Publishing](https://guides.rubygems.org/trusted-publishing/) (OIDC from GitHub Actions — no API key secret).
215
+
216
+ Because `zlight_csv` is not on RubyGems yet, register a **pending** trusted publisher:
217
+
218
+ 1. Sign in at [rubygems.org](https://rubygems.org/)
219
+ 2. Open [Pending trusted publishers](https://rubygems.org/profile/oidc/pending_trusted_publishers) → **Create**
220
+ 3. Set:
221
+ - **Gem name:** `zlight_csv`
222
+ - **Repository owner:** `zaidanch`
223
+ - **Repository name:** `zlight`
224
+ - **Workflow filename:** `release.yml`
225
+ 4. Save. The first successful workflow run will create the gem and add you as owner.
226
+
227
+ If publish fails with an auth error, confirm the workflow filename is exactly `release.yml` and matches what you registered on RubyGems.
228
+
229
+ **Important:** Trusted publishing only works after the updated `release.yml` is on GitHub (`main`). Older workflow runs used a `RUBYGEMS_API_KEY` secret and ignored your pending publisher.
230
+
231
+ If you set **Environment** to `release` on RubyGems, uncomment `environment: release` under the `release` job in `.github/workflows/release.yml`.
232
+
233
+ ### Re-run after pushing the workflow fix
234
+
235
+ ```bash
236
+ git push origin main
237
+ # Actions → Release → Run workflow (uses main; no tag required)
238
+ # or move the tag to the latest commit and push the tag again
239
+ ```
240
+
241
+ ### Manual Release (Local Build)
242
+
243
+ Build locally with Docker:
244
+
245
+ ```bash
246
+ # Install cross-compilation tools
247
+ gem install rake-compiler-dock
248
+
249
+ # Build for a single platform (requires Docker on the host)
250
+ rake dock:arm64-darwin
251
+
252
+ # Build for ALL platforms
253
+ rake dock:all
254
+
255
+ # Output in pkg/:
256
+ # zlight_csv-0.1.0-x86_64-linux.gem
257
+ # zlight_csv-0.1.0-arm64-darwin.gem
258
+ # zlight_csv-0.1.0-x64-mingw-ucrt.gem
259
+ # ... etc
260
+
261
+ # Push all gems to RubyGems
262
+ rake release:push
263
+ ```
264
+
265
+ ## Project Structure
266
+
267
+ ```
268
+ zlight-csv/
269
+ ├── ext/
270
+ │ └── zlight_csv/ # Rust native extension
271
+ │ ├── src/
272
+ │ │ ├── lib.rs # Entry point & Ruby bindings
273
+ │ │ ├── error.rs # Error types (enum-based)
274
+ │ │ ├── options.rs # Parse options handling
275
+ │ │ ├── parser.rs # CSV parsing logic
276
+ │ │ └── converter.rs # Type conversion utilities
277
+ │ ├── Cargo.toml # Rust dependencies
278
+ │ └── extconf.rb # Extension configuration
279
+ ├── lib/
280
+ │ ├── zlight_csv.rb # Main Ruby entry point
281
+ │ └── zlight_csv/
282
+ │ └── version.rb # Version constant
283
+ ├── spec/ # RSpec tests
284
+ ├── benchmark/ # Performance benchmarks
285
+ ├── Gemfile # Ruby dependencies
286
+ ├── Rakefile # Build tasks
287
+ ├── zlight_csv.gemspec # Gem specification
288
+ └── README.md
289
+ ```
290
+
291
+ ## API Compatibility with Ruby CSV
292
+
293
+ | Ruby CSV | ZLight | Status |
294
+ |----------|--------|--------|
295
+ | `CSV.parse(str, headers: true)` | `ZLight.parse(str, headers: true)` | ✅ |
296
+ | `CSV.parse(str, header_converters: :symbol)` | Automatic | ✅ |
297
+ | `CSV.parse(str, converters: :numeric)` | `ZLight.parse(str, converters: :numeric)` | ✅ |
298
+ | `CSV.read(path)` | `ZLight.read(path)` | ✅ |
299
+ | `CSV.foreach(str) { }` | `ZLight.foreach(str) { }` | ✅ |
300
+ | `CSV.parse(str, col_sep: "\t")` | `ZLight.parse(str, col_sep: "\t")` | ✅ |
301
+ | Streaming/lazy parsing | Not yet supported | 🚧 |
302
+ | Writing CSV | Not supported | ❌ |
303
+
304
+ ## Error Handling
305
+
306
+ ZLight provides descriptive error messages:
307
+
308
+ ```ruby
309
+ begin
310
+ ZLight.parse(invalid_csv)
311
+ rescue => e
312
+ puts e.class # RuntimeError, ArgumentError, EncodingError, etc.
313
+ puts e.message # Descriptive error message
314
+ end
315
+ ```
316
+
317
+ Error types:
318
+ - `ArgumentError` - Invalid arguments or options
319
+ - `EncodingError` - Invalid UTF-8 in headers
320
+ - `RuntimeError` - CSV parsing errors
321
+ - `IOError` - File reading errors
322
+
323
+ ## Contributing
324
+
325
+ 1. Fork the repository
326
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
327
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
328
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
329
+ 5. Open a Pull Request
330
+
331
+ ### Running Tests
332
+
333
+ ```bash
334
+ bundle exec rake spec
335
+ ```
336
+
337
+ ## License
338
+
339
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
340
+
341
+ ## Acknowledgments
342
+
343
+ - [csv](https://crates.io/crates/csv) - Rust CSV parsing library by BurntSushi
344
+ - [magnus](https://crates.io/crates/magnus) - Ruby bindings for Rust
345
+ - [rb-sys](https://github.com/oxidize-rb/rb-sys) - Ruby build system integration
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZLight
4
+ VERSION = '0.1.0'
5
+ end
data/lib/zlight_csv.rb ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'zlight_csv/version'
4
+
5
+ # Load the prebuilt native extension for this Ruby version
6
+ begin
7
+ ruby_version = RUBY_VERSION.match(/(\d+\.\d+)/)[1]
8
+ require_relative "zlight_csv/#{ruby_version}/zlight_csv"
9
+ rescue LoadError
10
+ require_relative 'zlight_csv/zlight_csv'
11
+ end
12
+
13
+ module ZLight
14
+ class Error < StandardError; end
15
+ class ParseError < Error; end
16
+ class EncodingError < Error; end
17
+
18
+ class << self
19
+ # Parses a CSV file and returns an array of hashes or arrays.
20
+ #
21
+ # @param path [String] Path to the CSV file
22
+ # @param options [Hash] Parsing options (same as .parse)
23
+ # @return [Array<Hash>, Array<Array>] Parsed CSV data
24
+ def read(path, **options)
25
+ parse(File.read(path, encoding: 'UTF-8'), **options)
26
+ end
27
+
28
+ # Iterates over each row in the CSV string.
29
+ #
30
+ # @param csv_string [String] The CSV data to parse
31
+ # @param options [Hash] Parsing options (same as .parse)
32
+ # @yield [row] Each row as a Hash or Array
33
+ # @return [Enumerator] If no block given
34
+ def foreach(csv_string, **options, &block)
35
+ return to_enum(:foreach, csv_string, **options) unless block_given?
36
+
37
+ parse(csv_string, **options).each(&block)
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zlight_csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: x64-mingw-ucrt
6
+ authors:
7
+ - Zaidan Chaudhary
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-05-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ ZLight is a blazing-fast CSV parser that provides a drop-in replacement
15
+ for Ruby's standard CSV library. Built with Rust for maximum performance,
16
+ it can parse CSV files up to 30x faster than the standard library while
17
+ maintaining full compatibility with common CSV.parse options.
18
+ email:
19
+ - zaidan@arxiron.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - CHANGELOG.md
25
+ - LICENSE
26
+ - README.md
27
+ - lib/zlight_csv.rb
28
+ - lib/zlight_csv/3.1/zlight_csv.so
29
+ - lib/zlight_csv/3.2/zlight_csv.so
30
+ - lib/zlight_csv/3.3/zlight_csv.so
31
+ - lib/zlight_csv/version.rb
32
+ homepage: https://arxiron.com
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://arxiron.com
37
+ source_code_uri: https://arxiron.com
38
+ changelog_uri: https://arxiron.com/blob/main/CHANGELOG.md
39
+ rubygems_mfa_required: 'true'
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '3.1'
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: 3.4.dev
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.5.23
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: High-performance CSV parser for Ruby, powered by Rust
62
+ test_files: []