xcsv 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9a8d5c371cffac1168bab3828f1e7f3853a859d5c4eef6ef8cda2e45aee2ed5
4
+ data.tar.gz: a03cd965c98b332e6c4b3dff1181d1b1bb959852958239f5da2389d12fe473db
5
+ SHA512:
6
+ metadata.gz: b8069138d85fea38fa096badd6055a37bfc3cc30dcf63d39240918fb65b282506352e1c95b8ae56e2dcb537399a0f9855cf84850680f978c1402e0baa61123c6
7
+ data.tar.gz: 5eb46dc0ddef820e462aa2bc0a2f4c8018517426238ecf8d33def906e1ff05e760edf2760be7fd73ee9b752a3c082291bfedffadc59215c29f591f10f7d66ff7
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /target
2
+ *.so
data/Cargo.lock ADDED
@@ -0,0 +1,89 @@
1
+ [[package]]
2
+ name = "cfg-if"
3
+ version = "0.1.6"
4
+ source = "registry+https://github.com/rust-lang/crates.io-index"
5
+
6
+ [[package]]
7
+ name = "cstr-macro"
8
+ version = "0.1.0"
9
+ source = "registry+https://github.com/rust-lang/crates.io-index"
10
+
11
+ [[package]]
12
+ name = "csv"
13
+ version = "1.0.2"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ dependencies = [
16
+ "csv-core 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
17
+ "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
18
+ ]
19
+
20
+ [[package]]
21
+ name = "csv-core"
22
+ version = "0.1.4"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ dependencies = [
25
+ "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
26
+ ]
27
+
28
+ [[package]]
29
+ name = "helix"
30
+ version = "0.7.5"
31
+ source = "registry+https://github.com/rust-lang/crates.io-index"
32
+ dependencies = [
33
+ "cstr-macro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
34
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
35
+ "libcruby-sys 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
36
+ ]
37
+
38
+ [[package]]
39
+ name = "libc"
40
+ version = "0.2.43"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+
43
+ [[package]]
44
+ name = "libcruby-sys"
45
+ version = "0.7.5"
46
+ source = "registry+https://github.com/rust-lang/crates.io-index"
47
+ dependencies = [
48
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
49
+ ]
50
+
51
+ [[package]]
52
+ name = "memchr"
53
+ version = "2.1.1"
54
+ source = "registry+https://github.com/rust-lang/crates.io-index"
55
+ dependencies = [
56
+ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
57
+ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
58
+ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
59
+ ]
60
+
61
+ [[package]]
62
+ name = "serde"
63
+ version = "1.0.80"
64
+ source = "registry+https://github.com/rust-lang/crates.io-index"
65
+
66
+ [[package]]
67
+ name = "version_check"
68
+ version = "0.1.5"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+
71
+ [[package]]
72
+ name = "xcsv"
73
+ version = "0.1.0"
74
+ dependencies = [
75
+ "csv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
76
+ "helix 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
77
+ ]
78
+
79
+ [metadata]
80
+ "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
81
+ "checksum cstr-macro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db53fddba18cdd35477a7213a3ef6acfbfa333c31b42ce019e544c4a1420a06f"
82
+ "checksum csv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d54f6b0fd69128a2894b1a3e57af5849a0963c1cc77b165d30b896e40296452"
83
+ "checksum csv-core 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4dd8e6d86f7ba48b4276ef1317edc8cc36167546d8972feb4a2b5fec0b374105"
84
+ "checksum helix 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "49a017e3e798ad9386e0a0584e66fd6c04a80ccc1242eb8f689c62ce6f408240"
85
+ "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
86
+ "checksum libcruby-sys 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fef6028cdce0c8d55676fd1d66bb810facef8cade0dd71d28511d375e84da4c0"
87
+ "checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
88
+ "checksum serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "15c141fc7027dd265a47c090bf864cf62b42c4d228bbcf4e51a0c9e2b0d3f7ef"
89
+ "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
data/Cargo.toml ADDED
@@ -0,0 +1,11 @@
1
+ [package]
2
+ name = "xcsv"
3
+ version = "0.1.0"
4
+ authors = ["Victor Moroz"]
5
+
6
+ [lib]
7
+ crate-type = ["cdylib"]
8
+
9
+ [dependencies]
10
+ helix = "0.7.5"
11
+ csv = "1.0.2"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xcsv (0.1.0)
5
+ helix_runtime (= 0.7.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ helix_runtime (0.7.5)
12
+ rake (>= 10.0)
13
+ thor (>= 0.19.4, < 2.0)
14
+ tomlrb (~> 1.2.4)
15
+ rake (12.3.1)
16
+ rspec (3.8.0)
17
+ rspec-core (~> 3.8.0)
18
+ rspec-expectations (~> 3.8.0)
19
+ rspec-mocks (~> 3.8.0)
20
+ rspec-core (3.8.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-expectations (3.8.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-mocks (3.8.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-support (3.8.0)
29
+ thor (0.20.3)
30
+ tomlrb (1.2.7)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.17)
37
+ xcsv!
38
+ rake (~> 12.3)
39
+ rspec (~> 3.8)
40
+
41
+ BUNDLED WITH
42
+ 1.17.1
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ Fast CSV reader based on [Rust CSV crate](https://docs.rs/csv/1.0.2/csv/)
2
+
3
+ ---
4
+
5
+ 1. Install [Rust](https://www.rust-lang.org/)
6
+
7
+ `curl https://sh.rustup.rs -sSf | sh`
8
+
9
+ Don't miss this message:
10
+
11
+ ```
12
+ Rust is installed now. Great!
13
+
14
+ To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
15
+ environment variable. Next time you log in this will be done automatically.
16
+
17
+ To configure your current shell run source $HOME/.cargo/env
18
+
19
+ ```
20
+
21
+ 2. `bundle exec rake`
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ require 'helix_runtime/build_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ HelixRuntime::BuildTask.new do |t|
6
+ end
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.verbose = false
10
+ end
11
+
12
+ task :default => :test
13
+ task :test => :build
data/extconfig.rb ADDED
@@ -0,0 +1,14 @@
1
+ abort "Rust compiler required (https://www.rust-lang.org/)" if `which rustc`.empty?
2
+
3
+ File.open("Makefile", "wb") do |f|
4
+
5
+ f.puts(<<EOD)
6
+ all:
7
+ \tbundle --deployment --path vendor/bundle
8
+ \tbundle exec rake
9
+ clean:
10
+ install:
11
+ \trm -r vendor/bundle target
12
+ EOD
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ class XCSV
2
+ VERSION = "0.1.0"
3
+ end
data/lib/xcsv.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'helix_runtime'
2
+ require 'xcsv/native'
data/src/lib.rs ADDED
@@ -0,0 +1,95 @@
1
+ extern crate csv;
2
+
3
+ #[macro_use]
4
+ extern crate helix;
5
+
6
+ use std::fs::File;
7
+ use std::io::BufReader;
8
+ use std::ops::{Deref, DerefMut};
9
+
10
+ use helix::{FromRuby, CheckResult};
11
+ use helix::sys::{VALUE};
12
+
13
+ type CSVIterType = Iterator<Item=Result<csv::StringRecord, csv::Error>>;
14
+
15
+ struct CSVIter {
16
+ iter: Box<CSVIterType>
17
+ }
18
+
19
+ impl Deref for CSVIter {
20
+ type Target = CSVIterType;
21
+
22
+ fn deref(&self) -> &CSVIterType {
23
+ &self.iter
24
+ }
25
+ }
26
+
27
+ impl DerefMut for CSVIter {
28
+ fn deref_mut(&mut self) -> &mut CSVIterType {
29
+ &mut self.iter
30
+ }
31
+ }
32
+
33
+ impl std::fmt::Debug for CSVIter {
34
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
35
+ write!(f, "CSVIter")
36
+ }
37
+ }
38
+
39
+ impl Clone for CSVIter {
40
+ fn clone(&self) -> CSVIter {
41
+ panic!("Not cloneable!")
42
+ }
43
+ }
44
+
45
+ impl FromRuby for CSVIter {
46
+ type Checked = CSVIter;
47
+
48
+ fn from_ruby(value: VALUE) -> CheckResult<CSVIter> {
49
+ let checked_path = String::from_ruby(value)?;
50
+
51
+ let csv_reader =
52
+ match File::open(String::from_checked(checked_path)) {
53
+ Ok(f) =>
54
+ BufReader::new(f),
55
+ Err(e) =>
56
+ raise!(format!("Error while opening file: {}", e)),
57
+ };
58
+
59
+ let csv_reader =
60
+ csv::ReaderBuilder::new()
61
+ .has_headers(false)
62
+ .from_reader(csv_reader);
63
+
64
+ let records = csv_reader.into_records();
65
+
66
+ Ok(CSVIter{iter: Box::new(records)})
67
+ }
68
+
69
+ fn from_checked(checked: CSVIter) -> CSVIter {
70
+ checked
71
+ }
72
+ }
73
+
74
+ ruby! {
75
+ class XCSV {
76
+ struct {
77
+ iter: CSVIter,
78
+ }
79
+
80
+ def initialize(helix, iter: CSVIter) {
81
+ XCSV { helix, iter }
82
+ }
83
+
84
+ def next_line(&mut self) -> Result<Option<Vec<String>>, helix::Error> {
85
+ match self.iter.next() {
86
+ Some(Ok(record)) =>
87
+ Ok(Some(record.iter().map(|s| s.to_string()).collect())),
88
+ Some(Err(e)) =>
89
+ raise!(e.to_string()),
90
+ None =>
91
+ Ok(None)
92
+ }
93
+ }
94
+ }
95
+ }
data/xcsv.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xcsv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xcsv"
8
+ spec.version = XCSV::VERSION
9
+ spec.authors = ["Victor Moroz"]
10
+
11
+ spec.summary = "Fast CSV reader"
12
+ spec.license = "MIT"
13
+
14
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
15
+ # delete this section to allow pushing this gem to any host.
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
18
+ else
19
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
20
+ end
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency "helix_runtime", "= 0.7.5"
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 12.3"
28
+ spec.add_development_dependency "rspec", "~> 3.8"
29
+
30
+ spec.extensions = %w[extconfig.rb]
31
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcsv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Moroz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: helix_runtime
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ description:
70
+ email:
71
+ executables: []
72
+ extensions:
73
+ - extconfig.rb
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Cargo.lock
78
+ - Cargo.toml
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - extconfig.rb
84
+ - lib/xcsv.rb
85
+ - lib/xcsv/version.rb
86
+ - src/lib.rs
87
+ - xcsv.gemspec
88
+ homepage:
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ allowed_push_host: https://rubygems.org
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.7.8
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Fast CSV reader
113
+ test_files: []