chunkio 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.
- checksums.yaml +7 -0
- data/.editorconfig +27 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +91 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE +202 -0
- data/README.md +35 -0
- data/Rakefile +14 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/chunkio.gemspec +33 -0
- data/ext/chunkio/chunkio.c +11 -0
- data/ext/chunkio/chunkio.h +60 -0
- data/ext/chunkio/chunkio_chunk.c +255 -0
- data/ext/chunkio/chunkio_context.c +68 -0
- data/ext/chunkio/chunkio_stream.c +56 -0
- data/ext/chunkio/extconf.rb +33 -0
- data/lib/chunkio.rb +14 -0
- data/lib/chunkio/chunkio.rb +35 -0
- data/lib/chunkio/version.rb +5 -0
- metadata +147 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fa3c1142ad70ce171d2c09a86fbc0c38a69509fcf1afac92ee8742eb78869b73
|
|
4
|
+
data.tar.gz: 135f9786066b57c26c0f50e254da44cba58c8217f429616695d8d7c5a21f5f75
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9da7a35b0b3eb323bbb79012e4425363e5c10471163d9602eadc5233d397c4d560a80ef44f8a8e7ca66feec74e254aef433442a5eea3ec09deb83e7a93a662d5
|
|
7
|
+
data.tar.gz: c7b26987992e1bad79bc65e7a71d6a60c6a9e2511342b28cb160cdbfcb75002183507c2aca5d7c7c4ebb8f863d8ee26596c8cef414371860e5ade681aa9dfd3a
|
data/.editorconfig
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
end_of_line = lf
|
|
5
|
+
indent_size = 4
|
|
6
|
+
indent_style = space
|
|
7
|
+
insert_final_newline = true
|
|
8
|
+
tab_width = 8
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.gemspec]
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
[*.rb]
|
|
15
|
+
indent_size = 2
|
|
16
|
+
|
|
17
|
+
[*.yml]
|
|
18
|
+
indent_size = 2
|
|
19
|
+
|
|
20
|
+
[{*[Mm]akefile*,*.mak,*.mk,depend}]
|
|
21
|
+
indent_style = tab
|
|
22
|
+
|
|
23
|
+
[enc/*]
|
|
24
|
+
indent_size = 2
|
|
25
|
+
|
|
26
|
+
[reg*.[ch]]
|
|
27
|
+
indent_size = 2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
Exclude:
|
|
3
|
+
- "vendor/**/*"
|
|
4
|
+
DisplayCopNames: true
|
|
5
|
+
TargetRubyVersion: 2.6
|
|
6
|
+
|
|
7
|
+
Style/AndOr:
|
|
8
|
+
EnforcedStyle: conditionals
|
|
9
|
+
|
|
10
|
+
Style/AsciiComments:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
Style/Documentation:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Style/DoubleNegation:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Style/EmptyElse:
|
|
20
|
+
EnforcedStyle: empty
|
|
21
|
+
|
|
22
|
+
Style/FormatString:
|
|
23
|
+
EnforcedStyle: percent
|
|
24
|
+
|
|
25
|
+
Style/IfUnlessModifier:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Style/TrailingCommaInHashLiteral:
|
|
29
|
+
EnforcedStyleForMultiline: comma
|
|
30
|
+
|
|
31
|
+
Style/TrailingCommaInArrayLiteral:
|
|
32
|
+
EnforcedStyleForMultiline: comma
|
|
33
|
+
|
|
34
|
+
Style/TrailingCommaInArguments:
|
|
35
|
+
EnforcedStyleForMultiline: comma
|
|
36
|
+
|
|
37
|
+
Style/SafeNavigation:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Style/WhileUntilModifier:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Naming/PredicateName:
|
|
44
|
+
NamePrefixBlacklist:
|
|
45
|
+
- "is_"
|
|
46
|
+
- "have_"
|
|
47
|
+
NamePrefix:
|
|
48
|
+
- "is_"
|
|
49
|
+
- "have_"
|
|
50
|
+
|
|
51
|
+
Style/SignalException:
|
|
52
|
+
EnforcedStyle: only_raise
|
|
53
|
+
|
|
54
|
+
Style/SingleLineBlockParams:
|
|
55
|
+
Enabled: false
|
|
56
|
+
|
|
57
|
+
Style/NumericLiterals:
|
|
58
|
+
Enabled: false
|
|
59
|
+
|
|
60
|
+
Style/GuardClause:
|
|
61
|
+
Enabled: false
|
|
62
|
+
|
|
63
|
+
Style/NumericPredicate:
|
|
64
|
+
Enabled: false
|
|
65
|
+
|
|
66
|
+
Metrics/ParameterLists:
|
|
67
|
+
CountKeywordArgs: false
|
|
68
|
+
|
|
69
|
+
Lint/UnderscorePrefixedVariableName:
|
|
70
|
+
Enabled: false
|
|
71
|
+
|
|
72
|
+
Metrics/AbcSize:
|
|
73
|
+
Max: 50
|
|
74
|
+
|
|
75
|
+
Metrics/CyclomaticComplexity:
|
|
76
|
+
Max: 10
|
|
77
|
+
|
|
78
|
+
Metrics/LineLength:
|
|
79
|
+
Max: 160
|
|
80
|
+
|
|
81
|
+
Metrics/MethodLength:
|
|
82
|
+
Max: 40
|
|
83
|
+
|
|
84
|
+
Metrics/PerceivedComplexity:
|
|
85
|
+
Max: 20
|
|
86
|
+
|
|
87
|
+
Metrics/ClassLength:
|
|
88
|
+
Max: 200
|
|
89
|
+
|
|
90
|
+
Metrics/BlockLength:
|
|
91
|
+
Max: 40
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2019 ganmacs
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Chunkio
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chunkio`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'chunkio'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install chunkio
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/chunkio.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rake/extensiontask'
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
|
|
7
|
+
task default: :compile
|
|
8
|
+
|
|
9
|
+
Rake::ExtensionTask.new('chunkio') do |t|
|
|
10
|
+
t.name = 'chunkio'
|
|
11
|
+
|
|
12
|
+
t.ext_dir = 'ext/chunkio'
|
|
13
|
+
t.lib_dir = 'lib'
|
|
14
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'chunkio'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/chunkio.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'chunkio/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'chunkio'
|
|
9
|
+
spec.version = ChunkIO::VERSION
|
|
10
|
+
spec.authors = ['Yuta Iwama']
|
|
11
|
+
spec.email = ['ganmacs@gmail.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'Wrapper of chunkio'
|
|
14
|
+
spec.description = 'Wrapper of chunkio'
|
|
15
|
+
spec.homepage = 'https://github.com/ganmacs/chunkio-rb'
|
|
16
|
+
|
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = 'exe'
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ['lib']
|
|
25
|
+
|
|
26
|
+
spec.add_runtime_dependency 'mini_portile2', '>= 2.2.0'
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
30
|
+
spec.add_development_dependency 'rake-compiler'
|
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
32
|
+
spec.add_development_dependency 'rubocop'
|
|
33
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#ifndef RB_CHUNKIO_CHUNKIO_H
|
|
2
|
+
#define RB_CHUNKIO_CHUNKIO_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include <chunkio/chunkio.h>
|
|
7
|
+
#include <chunkio/chunkio_compat.h>
|
|
8
|
+
#include <crc32/crc32.h>
|
|
9
|
+
#include <chunkio/cio_crc32.h>
|
|
10
|
+
#include <chunkio/cio_log.h>
|
|
11
|
+
#include <chunkio/cio_stream.h>
|
|
12
|
+
#include <chunkio/cio_chunk.h>
|
|
13
|
+
#include <chunkio/cio_meta.h>
|
|
14
|
+
#include <chunkio/cio_scan.h>
|
|
15
|
+
#include <chunkio/cio_utils.h>
|
|
16
|
+
|
|
17
|
+
typedef struct chunkio_chunk {
|
|
18
|
+
struct cio_chunk* inner;
|
|
19
|
+
int closed;
|
|
20
|
+
} chunkio_chunk;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
void *chunkio_context_free(struct cio_ctx *ctx);
|
|
24
|
+
void *chunkio_stream_free(struct cio_stream *st);
|
|
25
|
+
void *chunkio_chunk_free(chunkio_chunk *ch);
|
|
26
|
+
|
|
27
|
+
static const rb_data_type_t chunkio_context_type =
|
|
28
|
+
{
|
|
29
|
+
"ChunkIO::Context",
|
|
30
|
+
{0, (void (*)(void *))chunkio_context_free, 0,},
|
|
31
|
+
0, 0,
|
|
32
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
|
33
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
34
|
+
#endif
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
static const rb_data_type_t chunkio_stream_type =
|
|
38
|
+
{
|
|
39
|
+
"ChunkIO::Stream",
|
|
40
|
+
{0, (void (*)(void *))chunkio_stream_free, 0,},
|
|
41
|
+
0, 0,
|
|
42
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
|
43
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
44
|
+
#endif
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
static const rb_data_type_t chunkio_chunk_type =
|
|
48
|
+
{
|
|
49
|
+
"ChunkIO::Chunk",
|
|
50
|
+
{0, (void (*)(void *))chunkio_chunk_free, 0,}, /* TODO free ch->name and ch->head */
|
|
51
|
+
0, 0,
|
|
52
|
+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
|
|
53
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
54
|
+
#endif
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
struct cio_ctx *UnwrapChunkIOContext(VALUE self);
|
|
58
|
+
struct cio_stream* UnwrapChunkIOStream(VALUE self);
|
|
59
|
+
|
|
60
|
+
#endif
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#include <chunkio.h>
|
|
2
|
+
|
|
3
|
+
VALUE cCIO_Chunk;
|
|
4
|
+
|
|
5
|
+
void *chunkio_chunk_free(chunkio_chunk *ch)
|
|
6
|
+
{
|
|
7
|
+
if (ch->inner) {
|
|
8
|
+
cio_chunk_sync(ch->inner);
|
|
9
|
+
cio_chunk_close(ch->inner, CIO_FALSE);
|
|
10
|
+
ch->inner = NULL;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
xfree(ch);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static VALUE chunkio_chunk_allocate_context(VALUE klass)
|
|
17
|
+
{
|
|
18
|
+
chunkio_chunk *c = (chunkio_chunk *)xmalloc(sizeof(chunkio_chunk));
|
|
19
|
+
c->closed = 0;
|
|
20
|
+
return TypedData_Wrap_Struct(klass, &chunkio_chunk_type, c);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static VALUE chunkio_chunk_initialize(VALUE self, VALUE context, VALUE stream, VALUE name)
|
|
24
|
+
{
|
|
25
|
+
struct cio_ctx *ctx = UnwrapChunkIOContext(context);
|
|
26
|
+
struct cio_stream *st = UnwrapChunkIOStream(stream);
|
|
27
|
+
const char *c_name = RSTRING_PTR(name);
|
|
28
|
+
|
|
29
|
+
struct cio_chunk *chunk = cio_chunk_open(ctx, st, c_name, CIO_OPEN, 1000);
|
|
30
|
+
|
|
31
|
+
((chunkio_chunk*)DATA_PTR(self))->inner = chunk;
|
|
32
|
+
return self;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static VALUE chunkio_chunk_unlink(VALUE self)
|
|
36
|
+
{
|
|
37
|
+
chunkio_chunk *chunk = NULL;
|
|
38
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
39
|
+
if (chunk->closed) {
|
|
40
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (cio_chunk_unlink(chunk->inner) == -1) {
|
|
44
|
+
rb_raise(rb_eIOError, "Failed to unlink");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
chunk->closed = 1; /* mark as closed */
|
|
48
|
+
return Qnil;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static VALUE chunkio_chunk_close(VALUE self)
|
|
52
|
+
{
|
|
53
|
+
chunkio_chunk *chunk = NULL;
|
|
54
|
+
int type;
|
|
55
|
+
struct cio_file *cf;
|
|
56
|
+
|
|
57
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
58
|
+
if (!chunk->closed) {
|
|
59
|
+
cio_chunk_sync(chunk->inner);
|
|
60
|
+
type = chunk->inner->st->type;
|
|
61
|
+
if (type == CIO_STORE_FS) {
|
|
62
|
+
/* COPY form chunkio cio_file.c */
|
|
63
|
+
chunk->inner->st->type;
|
|
64
|
+
cf = (struct cio_file *)chunk->inner->backend;
|
|
65
|
+
close(cf->fd);
|
|
66
|
+
cf->fd = 0;
|
|
67
|
+
}
|
|
68
|
+
chunk->closed = 1; /* mark as close */
|
|
69
|
+
|
|
70
|
+
return Qnil;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return Qnil;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static VALUE chunkio_chunk_write(VALUE self, VALUE buf)
|
|
77
|
+
{
|
|
78
|
+
chunkio_chunk *chunk = NULL;
|
|
79
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
80
|
+
ssize_t len = RSTRING_LEN(buf);
|
|
81
|
+
if (chunk->closed) {
|
|
82
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
cio_chunk_write(chunk->inner, (void *)RSTRING_PTR(buf), len);
|
|
86
|
+
return INT2NUM(len);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* static VALUE chunkio_chunk_write_at(VALUE self, VALUE buf, VALUE offset) */
|
|
90
|
+
/* { */
|
|
91
|
+
/* chunkio_chunk *chunk = NULL; */
|
|
92
|
+
/* TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk); */
|
|
93
|
+
/* ssize_t len = RSTRING_LEN(buf); */
|
|
94
|
+
/* off_t os = NUM2INT(offset); */
|
|
95
|
+
|
|
96
|
+
/* int ret = cio_chunk_write_at(chunk, os, (void *)RSTRING_PTR(buf), len); */
|
|
97
|
+
/* return INT2NUM(len); */
|
|
98
|
+
/* } */
|
|
99
|
+
|
|
100
|
+
static VALUE chunkio_chunk_bytesize(VALUE self)
|
|
101
|
+
{
|
|
102
|
+
chunkio_chunk *chunk = NULL;
|
|
103
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
104
|
+
size_t size = cio_chunk_get_content_size(chunk->inner);
|
|
105
|
+
|
|
106
|
+
return INT2NUM(size);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static VALUE chunkio_chunk_set_metadata(VALUE self, VALUE buf)
|
|
110
|
+
{
|
|
111
|
+
chunkio_chunk *chunk = NULL;
|
|
112
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
113
|
+
if (chunk->closed) {
|
|
114
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
ssize_t len = RSTRING_LEN(buf);
|
|
118
|
+
int ret = cio_meta_write(chunk->inner, (void *)RSTRING_PTR(buf), len);
|
|
119
|
+
if (ret == -1) {
|
|
120
|
+
rb_raise(rb_eStandardError, "failed to set metadata");
|
|
121
|
+
}
|
|
122
|
+
return INT2NUM(len);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static VALUE chunkio_chunk_metadata(VALUE self)
|
|
126
|
+
{
|
|
127
|
+
chunkio_chunk *chunk = NULL;
|
|
128
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
129
|
+
if (chunk->closed) {
|
|
130
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
char *buf = NULL;
|
|
134
|
+
size_t size = 0;
|
|
135
|
+
|
|
136
|
+
/* cio_meta_chunk return -1 if size is 0... */
|
|
137
|
+
if (cio_meta_size(chunk->inner) == 0) {
|
|
138
|
+
return rb_str_new(0, 0);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
int ret = cio_meta_read(chunk->inner, &buf, &size);
|
|
142
|
+
if (ret == -1) {
|
|
143
|
+
rb_raise(rb_eStandardError, "failed to get metadata");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return rb_str_new(buf, size);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* static VALUE chunkio_chunk_pos(VALUE self) */
|
|
150
|
+
/* { */
|
|
151
|
+
/* chunkio_chunk *chunk; */
|
|
152
|
+
/* TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk); */
|
|
153
|
+
/* size_t pos = cio_chunk_get_content_end_pos(chunk); */
|
|
154
|
+
|
|
155
|
+
/* return INT2NUM(pos); */
|
|
156
|
+
/* } */
|
|
157
|
+
|
|
158
|
+
static VALUE chunkio_chunk_sync(VALUE self)
|
|
159
|
+
{
|
|
160
|
+
chunkio_chunk *chunk;
|
|
161
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
162
|
+
if (chunk->closed) {
|
|
163
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
size_t ret = cio_chunk_sync(chunk->inner);
|
|
167
|
+
if (ret == -1) {
|
|
168
|
+
rb_raise(rb_eStandardError, "failed to sync");
|
|
169
|
+
}
|
|
170
|
+
return Qnil;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static VALUE chunkio_chunk_get_data(VALUE self)
|
|
174
|
+
{
|
|
175
|
+
chunkio_chunk *chunk;
|
|
176
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
177
|
+
if (chunk->closed) {
|
|
178
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
char *buf = NULL;
|
|
182
|
+
size_t size = 0;
|
|
183
|
+
int ret = cio_chunk_get_content(chunk->inner, &buf, &size);
|
|
184
|
+
if (ret == -1) {
|
|
185
|
+
rb_raise(rb_eStandardError, "failed to get data");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return rb_str_new(buf, size);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static VALUE chunkio_chunk_tx_begin(VALUE self)
|
|
192
|
+
{
|
|
193
|
+
chunkio_chunk *chunk;
|
|
194
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
195
|
+
if (chunk->closed) {
|
|
196
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
int ret = cio_chunk_tx_begin(chunk->inner);
|
|
200
|
+
if (ret == -1) {
|
|
201
|
+
rb_raise(rb_eStandardError, "failed to begin transaction");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return Qnil;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static VALUE chunkio_chunk_tx_commit(VALUE self)
|
|
208
|
+
{
|
|
209
|
+
chunkio_chunk *chunk;
|
|
210
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
211
|
+
if (chunk->closed) {
|
|
212
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
int ret = cio_chunk_tx_commit(chunk->inner);
|
|
216
|
+
if (ret == -1) {
|
|
217
|
+
rb_raise(rb_eStandardError, "failed to commit transaction");
|
|
218
|
+
}
|
|
219
|
+
return Qnil;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static VALUE chunkio_chunk_tx_rollback(VALUE self)
|
|
223
|
+
{
|
|
224
|
+
chunkio_chunk *chunk;
|
|
225
|
+
TypedData_Get_Struct(self, chunkio_chunk, &chunkio_chunk_type, chunk);
|
|
226
|
+
if (chunk->closed) {
|
|
227
|
+
rb_raise(rb_eIOError, "IO was already closed");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
int ret = cio_chunk_tx_rollback(chunk->inner);
|
|
231
|
+
if (ret == -1) {
|
|
232
|
+
rb_raise(rb_eStandardError, "failed to rollback transaction");
|
|
233
|
+
}
|
|
234
|
+
return Qnil;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
void Init_chunkio_chunk(VALUE mChunkIO)
|
|
238
|
+
{
|
|
239
|
+
cCIO_Chunk = rb_define_class_under(mChunkIO, "Chunk", rb_cObject);
|
|
240
|
+
rb_define_alloc_func(cCIO_Chunk, chunkio_chunk_allocate_context);
|
|
241
|
+
|
|
242
|
+
rb_define_method(cCIO_Chunk, "initialize", chunkio_chunk_initialize, 3);
|
|
243
|
+
rb_define_method(cCIO_Chunk, "write", chunkio_chunk_write, 1);
|
|
244
|
+
rb_define_method(cCIO_Chunk, "unlink", chunkio_chunk_unlink, 0);
|
|
245
|
+
rb_define_method(cCIO_Chunk, "close", chunkio_chunk_close, 0);
|
|
246
|
+
rb_define_method(cCIO_Chunk, "bytesize", chunkio_chunk_bytesize, 0);
|
|
247
|
+
rb_define_method(cCIO_Chunk, "set_metadata", chunkio_chunk_set_metadata, 1);
|
|
248
|
+
rb_define_method(cCIO_Chunk, "metadata", chunkio_chunk_metadata, 0);
|
|
249
|
+
rb_define_method(cCIO_Chunk, "sync", chunkio_chunk_sync, 0);
|
|
250
|
+
rb_define_method(cCIO_Chunk, "data", chunkio_chunk_get_data, 0);
|
|
251
|
+
rb_define_method(cCIO_Chunk, "tx_begin", chunkio_chunk_tx_begin, 0);
|
|
252
|
+
rb_define_method(cCIO_Chunk, "tx_commit", chunkio_chunk_tx_commit, 0);
|
|
253
|
+
rb_define_method(cCIO_Chunk, "tx_rollback", chunkio_chunk_tx_rollback, 0);
|
|
254
|
+
/* rb_define_method(cCIO_Chunk, "write_at", chunkio_chunk_write_at, 2); */
|
|
255
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#include <chunkio.h>
|
|
2
|
+
|
|
3
|
+
VALUE cCIO_Context;
|
|
4
|
+
|
|
5
|
+
void *chunkio_context_free(struct cio_ctx *ctx)
|
|
6
|
+
{
|
|
7
|
+
/*
|
|
8
|
+
Don't call cio_stream_destroy_all(ctx).
|
|
9
|
+
cio_stream is freed by chunkio_stream.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
if (ctx) {
|
|
13
|
+
free(ctx->root_path);
|
|
14
|
+
free(ctx);
|
|
15
|
+
ctx = NULL;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static int log_cb(struct cio_ctx *ctx, int level, const char *file, int line, char *str)
|
|
20
|
+
{
|
|
21
|
+
(void) ctx;
|
|
22
|
+
|
|
23
|
+
printf("[chunkio] %-60s => %s:%i\n", str, file, line);
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
struct cio_ctx* UnwrapChunkIOContext(VALUE self)
|
|
28
|
+
{
|
|
29
|
+
struct cio_ctx *ctx;
|
|
30
|
+
TypedData_Get_Struct(self, struct cio_ctx, &chunkio_context_type, ctx);
|
|
31
|
+
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static VALUE allocate_context(VALUE klass)
|
|
36
|
+
{
|
|
37
|
+
return TypedData_Wrap_Struct(klass, &chunkio_context_type, 0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static VALUE chunkio_context_initialize(VALUE self, VALUE root)
|
|
41
|
+
{
|
|
42
|
+
char *p = RSTRING_PTR(root);
|
|
43
|
+
/* struct cio_ctx *ctx = cio_create(p, log_cb, CIO_DEBUG, 0); /\* TODO: flags, LOG *\/ */
|
|
44
|
+
struct cio_ctx *ctx = cio_create(p, NULL, CIO_DEBUG, 0); /* TODO: flags, LOG */
|
|
45
|
+
if (!ctx) {
|
|
46
|
+
rb_raise(rb_eStandardError, "failed to create cio_ctx");
|
|
47
|
+
}
|
|
48
|
+
DATA_PTR(self) = ctx;
|
|
49
|
+
return Qnil;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static VALUE chunkio_context_root_path(VALUE self)
|
|
53
|
+
{
|
|
54
|
+
struct cio_ctx *ctx;
|
|
55
|
+
TypedData_Get_Struct(self, struct cio_ctx, &chunkio_context_type, ctx);
|
|
56
|
+
|
|
57
|
+
return rb_str_new2(ctx->root_path);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
void Init_chunkio_context(VALUE mChunkIO)
|
|
62
|
+
{
|
|
63
|
+
cCIO_Context = rb_define_class_under(mChunkIO, "Context", rb_cObject);
|
|
64
|
+
rb_define_alloc_func(cCIO_Context, allocate_context);
|
|
65
|
+
|
|
66
|
+
rb_define_method(cCIO_Context, "initialize", chunkio_context_initialize, 1);
|
|
67
|
+
rb_define_method(cCIO_Context, "root_path", chunkio_context_root_path, 0);
|
|
68
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#include <chunkio.h>
|
|
2
|
+
|
|
3
|
+
VALUE cCIO_Stream;
|
|
4
|
+
|
|
5
|
+
void *chunkio_stream_free(struct cio_stream *st)
|
|
6
|
+
{
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
Don't call cio_chunk_close_stream(st).
|
|
10
|
+
cio_chunk is freed by chunkio_chunk.
|
|
11
|
+
*/
|
|
12
|
+
if (st) {
|
|
13
|
+
/* destroy stream */
|
|
14
|
+
mk_list_del(&st->_head);
|
|
15
|
+
free(st->name);
|
|
16
|
+
free(st);
|
|
17
|
+
st = NULL;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
struct cio_stream* UnwrapChunkIOStream(VALUE self)
|
|
22
|
+
{
|
|
23
|
+
struct cio_ctx *ctx;
|
|
24
|
+
TypedData_Get_Struct(self, struct cio_stream, &chunkio_stream_type, ctx);
|
|
25
|
+
|
|
26
|
+
return ctx;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static VALUE allocate_stream(VALUE klass)
|
|
30
|
+
{
|
|
31
|
+
return TypedData_Wrap_Struct(klass, &chunkio_stream_type, 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static VALUE chunkio_stream_initialize(VALUE self, VALUE context, VALUE name)
|
|
35
|
+
{
|
|
36
|
+
char *stream_name = RSTRING_PTR(name);
|
|
37
|
+
struct cio_ctx *ctx = UnwrapChunkIOContext(context);
|
|
38
|
+
struct cio_stream *st = cio_stream_create(ctx, stream_name, CIO_STORE_FS); /* TODO CIO_STORE_FS */
|
|
39
|
+
if (!st) {
|
|
40
|
+
rb_raise(rb_eStandardError, "chunkio: cannot create stream");
|
|
41
|
+
return Qnil;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
DATA_PTR(self) = st;
|
|
45
|
+
return Qnil;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
void Init_chunkio_stream(VALUE mChunkIO)
|
|
50
|
+
{
|
|
51
|
+
cCIO_Stream = rb_define_class_under(mChunkIO, "Stream", rb_cObject);
|
|
52
|
+
rb_define_alloc_func(cCIO_Stream, allocate_stream);
|
|
53
|
+
|
|
54
|
+
rb_define_method(cCIO_Stream, "initialize", chunkio_stream_initialize, 2);
|
|
55
|
+
/* rb_define_method(cCIO_Stream, "root_path", chunkio_stream_root_path, 0); */
|
|
56
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mkmf'
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'mini_portile2'
|
|
6
|
+
|
|
7
|
+
dir_config('chunkio')
|
|
8
|
+
message "Building chunkio\n"
|
|
9
|
+
recipe = MiniPortileCMake.new('chunkio', 'v0.0.1')
|
|
10
|
+
|
|
11
|
+
recipe.files << {
|
|
12
|
+
url: 'https://github.com/ganmacs/chunkio/tarball/4773b4e7d27c8b8396f797c09dd22db5ffadeda8',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
recipe.cook
|
|
16
|
+
$LIBPATH = ["#{recipe.path}/lib"] + $LIBPATH
|
|
17
|
+
$CPPFLAGS << " -I#{recipe.path}/include"
|
|
18
|
+
|
|
19
|
+
recipe.activate
|
|
20
|
+
|
|
21
|
+
unless have_header('chunkio/chunkio.h')
|
|
22
|
+
abort 'chunkio/chunkio.h is not found'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
unless have_library('chunkio-static')
|
|
26
|
+
abort 'libchunkio-static not found'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
unless have_library('cio-crc32')
|
|
30
|
+
abort 'libcio-crc32 not found'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
create_makefile 'chunkio'
|
data/lib/chunkio.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'chunkio.so'
|
|
4
|
+
require 'chunkio/version'
|
|
5
|
+
require 'chunkio/chunkio'
|
|
6
|
+
|
|
7
|
+
module ChunkIO
|
|
8
|
+
def self.new(context_path:, stream_name:)
|
|
9
|
+
::ChunkIO::ChunkIO.new(
|
|
10
|
+
context_path: context_path,
|
|
11
|
+
stream_name: stream_name,
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'chunkio.so'
|
|
4
|
+
|
|
5
|
+
module ChunkIO
|
|
6
|
+
class ChunkIO
|
|
7
|
+
def initialize(context_path:, stream_name:)
|
|
8
|
+
unless context_path
|
|
9
|
+
raise 'invalid'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
unless stream_name
|
|
13
|
+
raise 'stream'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
if context_path.empty?
|
|
17
|
+
raise 'context_path should be at least one char'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if stream_name.empty?
|
|
21
|
+
raise 'stream_name should be at least one char'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
@ctx = ::ChunkIO::Context.new(context_path)
|
|
25
|
+
@stream = ::ChunkIO::Stream.new(@ctx, stream_name)
|
|
26
|
+
@chunks = []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create_chunk(name:)
|
|
30
|
+
c = ::ChunkIO::Chunk.new(@ctx, @stream, name)
|
|
31
|
+
@chunks << c
|
|
32
|
+
c
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chunkio
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yuta Iwama
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-09-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: mini_portile2
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 2.2.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.2.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake-compiler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubocop
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: Wrapper of chunkio
|
|
98
|
+
email:
|
|
99
|
+
- ganmacs@gmail.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".editorconfig"
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".rspec"
|
|
107
|
+
- ".rubocop.yml"
|
|
108
|
+
- ".travis.yml"
|
|
109
|
+
- Gemfile
|
|
110
|
+
- LICENSE
|
|
111
|
+
- README.md
|
|
112
|
+
- Rakefile
|
|
113
|
+
- bin/console
|
|
114
|
+
- bin/setup
|
|
115
|
+
- chunkio.gemspec
|
|
116
|
+
- ext/chunkio/chunkio.c
|
|
117
|
+
- ext/chunkio/chunkio.h
|
|
118
|
+
- ext/chunkio/chunkio_chunk.c
|
|
119
|
+
- ext/chunkio/chunkio_context.c
|
|
120
|
+
- ext/chunkio/chunkio_stream.c
|
|
121
|
+
- ext/chunkio/extconf.rb
|
|
122
|
+
- lib/chunkio.rb
|
|
123
|
+
- lib/chunkio/chunkio.rb
|
|
124
|
+
- lib/chunkio/version.rb
|
|
125
|
+
homepage: https://github.com/ganmacs/chunkio-rb
|
|
126
|
+
licenses: []
|
|
127
|
+
metadata: {}
|
|
128
|
+
post_install_message:
|
|
129
|
+
rdoc_options: []
|
|
130
|
+
require_paths:
|
|
131
|
+
- lib
|
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
|
+
requirements:
|
|
139
|
+
- - ">="
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '0'
|
|
142
|
+
requirements: []
|
|
143
|
+
rubygems_version: 3.0.3
|
|
144
|
+
signing_key:
|
|
145
|
+
specification_version: 4
|
|
146
|
+
summary: Wrapper of chunkio
|
|
147
|
+
test_files: []
|