zsv 1.4.4-x86_64-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
data/ext/zsv/parser.h
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* Parser wrapper around zsv */
|
|
2
|
+
#ifndef ZSV_RUBY_PARSER_H
|
|
3
|
+
#define ZSV_RUBY_PARSER_H
|
|
4
|
+
|
|
5
|
+
#include "common.h"
|
|
6
|
+
#include "options.h"
|
|
7
|
+
#include "row.h"
|
|
8
|
+
|
|
9
|
+
/* Where the parser reads its input from */
|
|
10
|
+
typedef enum {
|
|
11
|
+
ZSV_SOURCE_NONE = 0, /* not initialized yet */
|
|
12
|
+
ZSV_SOURCE_FILE, /* FILE* opened from a path */
|
|
13
|
+
ZSV_SOURCE_STRING, /* frozen Ruby String held in `source` */
|
|
14
|
+
ZSV_SOURCE_IO, /* Ruby object responding to #read held in `source` */
|
|
15
|
+
} zsv_source_kind_t;
|
|
16
|
+
|
|
17
|
+
/* Parser state, owned by a ZSV::Parser TypedData object. Every VALUE here is
|
|
18
|
+
* marked by zsv_parser_mark(); the struct is freed by zsv_parser_free(). */
|
|
19
|
+
typedef struct {
|
|
20
|
+
zsv_parser zsv; /* zsv parser instance */
|
|
21
|
+
zsv_source_kind_t source_kind; /* Input kind */
|
|
22
|
+
FILE *file; /* File handle (ZSV_SOURCE_FILE) */
|
|
23
|
+
VALUE source; /* String or IO object (pinned: zsv reads from it) */
|
|
24
|
+
size_t source_offset; /* Read position in a String source */
|
|
25
|
+
zsv_ruby_options_t options; /* Parser options */
|
|
26
|
+
zsv_row_builder_t *row_builder; /* Row builder */
|
|
27
|
+
VALUE row_buffer; /* Buffer of parsed rows (Ruby array) */
|
|
28
|
+
VALUE headers; /* Parsed headers (if header mode) */
|
|
29
|
+
size_t record_count; /* Records zsv has emitted: the 1-based line in errors */
|
|
30
|
+
size_t lines_skipped; /* Number of lines skipped */
|
|
31
|
+
bool header_row_processed; /* Whether header row was processed */
|
|
32
|
+
bool closed; /* Whether parser is closed */
|
|
33
|
+
bool eof_reached; /* Whether EOF (and zsv_finish) was reached */
|
|
34
|
+
bool parsing; /* True while inside zsv (reentrancy guard) */
|
|
35
|
+
bool column_overflow; /* zsv reported a row wider than max_columns */
|
|
36
|
+
bool row_truncated; /* zsv reported a row that did not fit in its buffer */
|
|
37
|
+
int exception_state; /* rb_protect state of an exception raised in a callback */
|
|
38
|
+
} zsv_ruby_parser_t;
|
|
39
|
+
|
|
40
|
+
/* Initialize symbols (called from Init_zsv) */
|
|
41
|
+
void Init_zsv_parser(void);
|
|
42
|
+
|
|
43
|
+
/* Reset a freshly allocated struct to the uninitialized state */
|
|
44
|
+
void zsv_parser_init_struct(zsv_ruby_parser_t *parser);
|
|
45
|
+
|
|
46
|
+
/* Initialize an allocated parser from a file path, String or IO object.
|
|
47
|
+
* May raise; the parser is then left for zsv_parser_free() to clean up. */
|
|
48
|
+
void zsv_parser_init_path(zsv_ruby_parser_t *parser, VALUE path, VALUE opts_hash);
|
|
49
|
+
void zsv_parser_init_string(zsv_ruby_parser_t *parser, VALUE string, VALUE opts_hash);
|
|
50
|
+
void zsv_parser_init_io(zsv_ruby_parser_t *parser, VALUE io, VALUE opts_hash);
|
|
51
|
+
|
|
52
|
+
/* GC support */
|
|
53
|
+
void zsv_parser_mark(zsv_ruby_parser_t *parser);
|
|
54
|
+
void zsv_parser_compact(zsv_ruby_parser_t *parser);
|
|
55
|
+
size_t zsv_parser_memsize(const zsv_ruby_parser_t *parser);
|
|
56
|
+
|
|
57
|
+
/* Free parser and associated resources */
|
|
58
|
+
void zsv_parser_free(zsv_ruby_parser_t *parser);
|
|
59
|
+
|
|
60
|
+
/* Parse next row, returns Ruby array or hash, or nil at EOF */
|
|
61
|
+
VALUE zsv_parser_shift(zsv_ruby_parser_t *parser);
|
|
62
|
+
|
|
63
|
+
/* Rewind parser to beginning */
|
|
64
|
+
void zsv_parser_rewind(zsv_ruby_parser_t *parser);
|
|
65
|
+
|
|
66
|
+
/* Close parser */
|
|
67
|
+
void zsv_parser_close(zsv_ruby_parser_t *parser);
|
|
68
|
+
|
|
69
|
+
/* Get headers */
|
|
70
|
+
VALUE zsv_parser_headers(zsv_ruby_parser_t *parser);
|
|
71
|
+
|
|
72
|
+
/* Check if parser is closed */
|
|
73
|
+
bool zsv_parser_closed(zsv_ruby_parser_t *parser);
|
|
74
|
+
|
|
75
|
+
#endif /* ZSV_RUBY_PARSER_H */
|
data/ext/zsv/row.c
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/* Row handling and conversion implementation */
|
|
2
|
+
#include "row.h"
|
|
3
|
+
|
|
4
|
+
#define INITIAL_ROW_CAPACITY 32
|
|
5
|
+
|
|
6
|
+
zsv_row_builder_t *zsv_row_builder_new(rb_encoding *encoding)
|
|
7
|
+
{
|
|
8
|
+
zsv_row_builder_t *builder = ZSV_ALLOC(zsv_row_builder_t);
|
|
9
|
+
|
|
10
|
+
builder->capacity = INITIAL_ROW_CAPACITY;
|
|
11
|
+
builder->cells = ZSV_ALLOC_N(VALUE, builder->capacity);
|
|
12
|
+
builder->count = 0;
|
|
13
|
+
builder->headers = Qnil;
|
|
14
|
+
builder->has_duplicate_headers = false;
|
|
15
|
+
builder->encoding = encoding;
|
|
16
|
+
|
|
17
|
+
return builder;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void zsv_row_builder_free(zsv_row_builder_t *builder)
|
|
21
|
+
{
|
|
22
|
+
if (builder) {
|
|
23
|
+
xfree(builder->cells);
|
|
24
|
+
xfree(builder);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void zsv_row_builder_mark(zsv_row_builder_t *builder)
|
|
29
|
+
{
|
|
30
|
+
rb_gc_mark_movable(builder->headers);
|
|
31
|
+
for (size_t i = 0; i < builder->count; i++) {
|
|
32
|
+
rb_gc_mark_movable(builder->cells[i]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void zsv_row_builder_compact(zsv_row_builder_t *builder)
|
|
37
|
+
{
|
|
38
|
+
builder->headers = rb_gc_location(builder->headers);
|
|
39
|
+
for (size_t i = 0; i < builder->count; i++) {
|
|
40
|
+
builder->cells[i] = rb_gc_location(builder->cells[i]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
size_t zsv_row_builder_memsize(const zsv_row_builder_t *builder)
|
|
45
|
+
{
|
|
46
|
+
return sizeof(*builder) + builder->capacity * sizeof(VALUE);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void zsv_row_builder_reset(zsv_row_builder_t *builder)
|
|
50
|
+
{
|
|
51
|
+
builder->count = 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static void zsv_row_builder_ensure_capacity(zsv_row_builder_t *builder, size_t needed)
|
|
55
|
+
{
|
|
56
|
+
if (needed <= builder->capacity) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Double capacity until we have enough */
|
|
61
|
+
size_t new_capacity = builder->capacity;
|
|
62
|
+
while (new_capacity < needed) {
|
|
63
|
+
new_capacity *= 2;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ZSV_REALLOC_N(builder->cells, VALUE, new_capacity);
|
|
67
|
+
builder->capacity = new_capacity;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void zsv_row_builder_add_cell(zsv_row_builder_t *builder, const unsigned char *data, size_t length)
|
|
71
|
+
{
|
|
72
|
+
zsv_row_builder_ensure_capacity(builder, builder->count + 1);
|
|
73
|
+
|
|
74
|
+
/* Create Ruby string with proper encoding. The allocation may run GC,
|
|
75
|
+
* which is why the cells collected so far are marked by the parser. */
|
|
76
|
+
VALUE str = rb_enc_str_new((const char *)data, length, builder->encoding);
|
|
77
|
+
|
|
78
|
+
/* Freeze string for memory efficiency (shared strings) */
|
|
79
|
+
rb_str_freeze(str);
|
|
80
|
+
|
|
81
|
+
builder->cells[builder->count++] = str;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
VALUE zsv_row_builder_to_array(zsv_row_builder_t *builder)
|
|
85
|
+
{
|
|
86
|
+
return rb_ary_new_from_values(builder->count, builder->cells);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
VALUE zsv_row_builder_to_hash(zsv_row_builder_t *builder)
|
|
90
|
+
{
|
|
91
|
+
if (NIL_P(builder->headers)) {
|
|
92
|
+
rb_raise(rb_eRuntimeError, "Headers not set for hash conversion");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* RARRAY_AREF, not a cached RARRAY_CONST_PTR: rb_hash_aset can trigger
|
|
96
|
+
* GC with auto-compaction, which may move an embedded array's storage */
|
|
97
|
+
VALUE headers = builder->headers;
|
|
98
|
+
size_t header_count = RARRAY_LEN(builder->headers);
|
|
99
|
+
size_t cell_count = builder->count;
|
|
100
|
+
|
|
101
|
+
/* Pre-allocate hash with expected size (Ruby 3.2+) */
|
|
102
|
+
#ifdef HAVE_RB_HASH_NEW_CAPA
|
|
103
|
+
VALUE hash = rb_hash_new_capa(header_count > cell_count ? header_count : cell_count);
|
|
104
|
+
#else
|
|
105
|
+
VALUE hash = rb_hash_new();
|
|
106
|
+
#endif
|
|
107
|
+
|
|
108
|
+
/* Like CSV, every header is a key; missing trailing fields are nil */
|
|
109
|
+
for (size_t i = 0; i < header_count; i++) {
|
|
110
|
+
VALUE header = RARRAY_AREF(headers, i);
|
|
111
|
+
if (builder->has_duplicate_headers && rb_hash_lookup2(hash, header, Qundef) != Qundef) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
rb_hash_aset(hash, header, i < cell_count ? builder->cells[i] : Qnil);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Rare case: more cells than headers, add with numeric keys */
|
|
118
|
+
for (size_t i = header_count; i < cell_count; i++) {
|
|
119
|
+
rb_hash_aset(hash, SIZET2NUM(i), builder->cells[i]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return hash;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Header strings are copied and frozen so that the caller mutating its
|
|
126
|
+
* header array (or the strings in it) cannot change the keys mid-parse, and
|
|
127
|
+
* so rb_hash_aset does not have to dup an unfrozen String key on every row. */
|
|
128
|
+
static VALUE zsv_row_builder_freeze_headers(VALUE headers)
|
|
129
|
+
{
|
|
130
|
+
long count = RARRAY_LEN(headers);
|
|
131
|
+
VALUE copy = rb_ary_new_capa(count);
|
|
132
|
+
|
|
133
|
+
for (long i = 0; i < count; i++) {
|
|
134
|
+
VALUE header = RARRAY_AREF(headers, i);
|
|
135
|
+
rb_ary_push(copy, RB_TYPE_P(header, T_STRING) ? rb_str_new_frozen(header) : header);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return rb_ary_freeze(copy);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static bool zsv_row_builder_has_duplicates(VALUE headers)
|
|
142
|
+
{
|
|
143
|
+
long count = RARRAY_LEN(headers);
|
|
144
|
+
VALUE seen = rb_hash_new();
|
|
145
|
+
|
|
146
|
+
for (long i = 0; i < count; i++) {
|
|
147
|
+
VALUE header = RARRAY_AREF(headers, i);
|
|
148
|
+
if (rb_hash_lookup2(seen, header, Qundef) != Qundef) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
rb_hash_aset(seen, header, Qtrue);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
void zsv_row_builder_set_headers(zsv_row_builder_t *builder, VALUE headers)
|
|
158
|
+
{
|
|
159
|
+
if (NIL_P(headers)) {
|
|
160
|
+
builder->headers = Qnil;
|
|
161
|
+
builder->has_duplicate_headers = false;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
Check_Type(headers, T_ARRAY);
|
|
166
|
+
VALUE frozen = zsv_row_builder_freeze_headers(headers);
|
|
167
|
+
builder->has_duplicate_headers = zsv_row_builder_has_duplicates(frozen);
|
|
168
|
+
builder->headers = frozen;
|
|
169
|
+
}
|
data/ext/zsv/row.h
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* Row handling and conversion */
|
|
2
|
+
#ifndef ZSV_RUBY_ROW_H
|
|
3
|
+
#define ZSV_RUBY_ROW_H
|
|
4
|
+
|
|
5
|
+
#include "common.h"
|
|
6
|
+
|
|
7
|
+
/* Row builder for efficient conversion from zsv cells to Ruby arrays/hashes.
|
|
8
|
+
* Every VALUE held here is reachable only through the C struct, so the owning
|
|
9
|
+
* parser must call zsv_row_builder_mark() and zsv_row_builder_compact(). */
|
|
10
|
+
typedef struct {
|
|
11
|
+
VALUE *cells; /* Ruby string cells of the current row */
|
|
12
|
+
size_t count; /* Number of cells in current row */
|
|
13
|
+
size_t capacity; /* Allocated capacity */
|
|
14
|
+
VALUE headers; /* Private frozen copy of the headers (hash mode) */
|
|
15
|
+
bool has_duplicate_headers; /* First occurrence wins, as in CSV::Row#to_h */
|
|
16
|
+
rb_encoding *encoding; /* String encoding */
|
|
17
|
+
} zsv_row_builder_t;
|
|
18
|
+
|
|
19
|
+
/* Initialize row builder */
|
|
20
|
+
zsv_row_builder_t *zsv_row_builder_new(rb_encoding *encoding);
|
|
21
|
+
|
|
22
|
+
/* Free row builder */
|
|
23
|
+
void zsv_row_builder_free(zsv_row_builder_t *builder);
|
|
24
|
+
|
|
25
|
+
/* GC support */
|
|
26
|
+
void zsv_row_builder_mark(zsv_row_builder_t *builder);
|
|
27
|
+
void zsv_row_builder_compact(zsv_row_builder_t *builder);
|
|
28
|
+
size_t zsv_row_builder_memsize(const zsv_row_builder_t *builder);
|
|
29
|
+
|
|
30
|
+
/* Reset row builder for next row */
|
|
31
|
+
void zsv_row_builder_reset(zsv_row_builder_t *builder);
|
|
32
|
+
|
|
33
|
+
/* Add cell to current row */
|
|
34
|
+
void zsv_row_builder_add_cell(zsv_row_builder_t *builder, const unsigned char *data, size_t length);
|
|
35
|
+
|
|
36
|
+
/* Build Ruby array from current row */
|
|
37
|
+
VALUE zsv_row_builder_to_array(zsv_row_builder_t *builder);
|
|
38
|
+
|
|
39
|
+
/* Build Ruby hash from current row (requires headers) */
|
|
40
|
+
VALUE zsv_row_builder_to_hash(zsv_row_builder_t *builder);
|
|
41
|
+
|
|
42
|
+
/* Set headers for hash mode (Qnil clears them) */
|
|
43
|
+
void zsv_row_builder_set_headers(zsv_row_builder_t *builder, VALUE headers);
|
|
44
|
+
|
|
45
|
+
#endif /* ZSV_RUBY_ROW_H */
|
data/ext/zsv/upstream.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The pinned upstream zsv release, shared by the Rakefile (which vendors it)
|
|
4
|
+
# and extconf.rb (which builds it). The pin itself lives in ZSV_UPSTREAM.
|
|
5
|
+
module ZSVUpstream
|
|
6
|
+
PIN_FILE = File.expand_path('ZSV_UPSTREAM', __dir__)
|
|
7
|
+
VENDOR_DIR = File.expand_path('vendor/zsv', __dir__)
|
|
8
|
+
# Written into VENDOR_DIR by `rake zsv:vendor`; records which pin it came from.
|
|
9
|
+
MARKER_FILE = File.join(VENDOR_DIR, 'VENDORED_FROM')
|
|
10
|
+
# The only parts of the upstream tarball needed to build libzsv.
|
|
11
|
+
VENDORED_PATHS = %w[LICENSE configure include src].freeze
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# @return [Hash{String => String}] the pin, e.g. {'version' => '1.4.4', 'sha256' => '...'}
|
|
16
|
+
def pin(path = PIN_FILE)
|
|
17
|
+
entries = File.readlines(path, chomp: true).reject { |line| line.strip.empty? || line.start_with?('#') }
|
|
18
|
+
pin = entries.to_h { |line| line.split('=', 2).map(&:strip) }
|
|
19
|
+
validate!(pin, path)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def version
|
|
23
|
+
pin.fetch('version')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def sha256
|
|
27
|
+
pin.fetch('sha256')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def tarball_url(version = self.version)
|
|
31
|
+
"https://github.com/liquidaty/zsv/archive/refs/tags/v#{version}.tar.gz"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [String, nil] contents of the marker, nil when nothing is vendored
|
|
35
|
+
def vendored_marker
|
|
36
|
+
File.read(MARKER_FILE) if File.file?(MARKER_FILE)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def marker_for(pin)
|
|
40
|
+
"version=#{pin.fetch('version')}\nsha256=#{pin.fetch('sha256')}\n"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def vendored_current?
|
|
44
|
+
vendored_marker == marker_for(pin)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def validate!(pin, path)
|
|
48
|
+
raise ArgumentError, "#{path}: version must look like 1.2.3, got #{pin['version'].inspect}" \
|
|
49
|
+
unless pin['version'].to_s.match?(/\A\d+(\.\d+){2}\z/)
|
|
50
|
+
raise ArgumentError, "#{path}: sha256 must be 64 hex characters, got #{pin['sha256'].inspect}" \
|
|
51
|
+
unless pin['sha256'].to_s.match?(/\A\h{64}\z/)
|
|
52
|
+
|
|
53
|
+
pin
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Guarnerix Inc dba Liquidaty
|
|
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.
|