yajl-ruby 0.7.1 → 0.7.2
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.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- data/CHANGELOG.md +8 -1
- data/MIT-LICENSE +3 -3
- data/README.rdoc +8 -8
- data/VERSION.yml +1 -1
- data/benchmark/subjects/ohai.yml +171 -171
- data/ext/api/yajl_common.h +9 -9
- data/ext/api/yajl_gen.h +10 -10
- data/ext/api/yajl_parse.h +15 -15
- data/ext/yajl.c +8 -8
- data/ext/yajl_alloc.c +6 -6
- data/ext/yajl_alloc.h +6 -6
- data/ext/yajl_buf.c +7 -7
- data/ext/yajl_buf.h +7 -7
- data/ext/yajl_bytestack.h +10 -10
- data/ext/yajl_encode.c +12 -12
- data/ext/yajl_encode.h +6 -6
- data/ext/yajl_ext.c +67 -80
- data/ext/yajl_ext.h +4 -4
- data/ext/yajl_gen.c +16 -16
- data/ext/yajl_lex.c +79 -76
- data/ext/yajl_lex.h +14 -14
- data/ext/yajl_parser.c +34 -34
- data/ext/yajl_parser.h +7 -7
- data/lib/yajl.rb +7 -7
- data/lib/yajl/bzip2/stream_reader.rb +1 -11
- data/lib/yajl/bzip2/stream_writer.rb +1 -1
- data/lib/yajl/deflate/stream_reader.rb +6 -7
- data/lib/yajl/deflate/stream_writer.rb +2 -2
- data/lib/yajl/gzip/stream_reader.rb +0 -10
- data/lib/yajl/http_stream.rb +12 -12
- data/lib/yajl/json_gem/encoding.rb +4 -4
- data/lib/yajl/json_gem/parsing.rb +3 -3
- data/spec/encoding/encoding_spec.rb +23 -23
- data/spec/global/global_spec.rb +8 -8
- data/spec/http/http_delete_spec.rb +13 -13
- data/spec/http/http_error_spec.rb +2 -2
- data/spec/http/http_get_spec.rb +15 -15
- data/spec/http/http_post_spec.rb +12 -12
- data/spec/http/http_put_spec.rb +14 -14
- data/spec/json_gem_compatibility/compatibility_spec.rb +21 -21
- data/spec/parsing/active_support_spec.rb +6 -6
- data/spec/parsing/chunked_spec.rb +12 -12
- data/spec/parsing/fixtures_spec.rb +4 -4
- data/spec/parsing/one_off_spec.rb +9 -9
- data/yajl-ruby.gemspec +3 -3
- metadata +12 -5
data/ext/yajl_lex.h
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
-
*
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#ifndef __YAJL_LEX_H__
|
34
34
|
#define __YAJL_LEX_H__
|
@@ -36,21 +36,21 @@
|
|
36
36
|
#include "api/yajl_common.h"
|
37
37
|
|
38
38
|
typedef enum {
|
39
|
-
yajl_tok_bool,
|
39
|
+
yajl_tok_bool,
|
40
40
|
yajl_tok_colon,
|
41
|
-
yajl_tok_comma,
|
41
|
+
yajl_tok_comma,
|
42
42
|
yajl_tok_eof,
|
43
43
|
yajl_tok_error,
|
44
|
-
yajl_tok_left_brace,
|
44
|
+
yajl_tok_left_brace,
|
45
45
|
yajl_tok_left_bracket,
|
46
|
-
yajl_tok_null,
|
47
|
-
yajl_tok_right_brace,
|
46
|
+
yajl_tok_null,
|
47
|
+
yajl_tok_right_brace,
|
48
48
|
yajl_tok_right_bracket,
|
49
49
|
|
50
50
|
/* we differentiate between integers and doubles to allow the
|
51
51
|
* parser to interpret the number without re-scanning */
|
52
|
-
yajl_tok_integer,
|
53
|
-
yajl_tok_double,
|
52
|
+
yajl_tok_integer,
|
53
|
+
yajl_tok_double,
|
54
54
|
|
55
55
|
/* we differentiate between strings which require further processing,
|
56
56
|
* and strings that do not */
|
@@ -83,7 +83,7 @@ n * error messages.
|
|
83
83
|
*
|
84
84
|
* When you pass the next chunk of data, context should be reinitialized
|
85
85
|
* to zero.
|
86
|
-
*
|
86
|
+
*
|
87
87
|
* Finally, the output buffer is usually just a pointer into the jsonText,
|
88
88
|
* however in cases where the entity being lexed spans multiple chunks,
|
89
89
|
* the lexer will buffer the entity and the data returned will be
|
data/ext/yajl_parser.c
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
-
*
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#include "yajl_lex.h"
|
34
34
|
#include "yajl_parser.h"
|
@@ -53,7 +53,7 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
|
|
53
53
|
const char * errorType = NULL;
|
54
54
|
const char * errorText = NULL;
|
55
55
|
char text[72];
|
56
|
-
const char * arrow = " (right here) ------^\n";
|
56
|
+
const char * arrow = " (right here) ------^\n";
|
57
57
|
|
58
58
|
if (yajl_bs_current(hand->stateStack) == yajl_state_parse_error) {
|
59
59
|
errorType = "parse";
|
@@ -70,18 +70,18 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
|
|
70
70
|
memneeded += strlen(errorType);
|
71
71
|
memneeded += strlen(" error");
|
72
72
|
if (errorText != NULL) {
|
73
|
-
memneeded += strlen(": ");
|
74
|
-
memneeded += strlen(errorText);
|
73
|
+
memneeded += strlen(": ");
|
74
|
+
memneeded += strlen(errorText);
|
75
75
|
}
|
76
76
|
str = (unsigned char *) YA_MALLOC(&(hand->alloc), memneeded + 2);
|
77
77
|
str[0] = 0;
|
78
78
|
strcat((char *) str, errorType);
|
79
|
-
strcat((char *) str, " error");
|
79
|
+
strcat((char *) str, " error");
|
80
80
|
if (errorText != NULL) {
|
81
|
-
strcat((char *) str, ": ");
|
82
|
-
strcat((char *) str, errorText);
|
81
|
+
strcat((char *) str, ": ");
|
82
|
+
strcat((char *) str, errorText);
|
83
83
|
}
|
84
|
-
strcat((char *) str, "\n");
|
84
|
+
strcat((char *) str, "\n");
|
85
85
|
}
|
86
86
|
|
87
87
|
/* now we append as many spaces as needed to make sure the error
|
@@ -93,7 +93,7 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
|
|
93
93
|
spacesNeeded = (offset < 30 ? 40 - offset : 10);
|
94
94
|
start = (offset >= 30 ? offset - 30 : 0);
|
95
95
|
end = (offset + 30 > jsonTextLen ? jsonTextLen : offset + 30);
|
96
|
-
|
96
|
+
|
97
97
|
for (i=0;i<spacesNeeded;i++) text[i] = ' ';
|
98
98
|
|
99
99
|
for (;start < end;start++, i++) {
|
@@ -117,7 +117,7 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText,
|
|
117
117
|
newStr[0] = 0;
|
118
118
|
strcat((char *) newStr, (char *) str);
|
119
119
|
strcat((char *) newStr, text);
|
120
|
-
strcat((char *) newStr, arrow);
|
120
|
+
strcat((char *) newStr, arrow);
|
121
121
|
YA_FREE(&(hand->alloc), str);
|
122
122
|
str = (unsigned char *) newStr;
|
123
123
|
}
|
@@ -148,7 +148,7 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
148
148
|
case yajl_state_parse_complete:
|
149
149
|
return yajl_status_ok;
|
150
150
|
case yajl_state_lexical_error:
|
151
|
-
case yajl_state_parse_error:
|
151
|
+
case yajl_state_parse_error:
|
152
152
|
hand->errorOffset = *offset;
|
153
153
|
return yajl_status_error;
|
154
154
|
case yajl_state_start:
|
@@ -187,13 +187,13 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
187
187
|
yajl_buf_len(hand->decodeBuf)));
|
188
188
|
}
|
189
189
|
break;
|
190
|
-
case yajl_tok_bool:
|
190
|
+
case yajl_tok_bool:
|
191
191
|
if (hand->callbacks && hand->callbacks->yajl_boolean) {
|
192
192
|
_CC_CHK(hand->callbacks->yajl_boolean(hand->ctx,
|
193
193
|
*buf == 't'));
|
194
194
|
}
|
195
195
|
break;
|
196
|
-
case yajl_tok_null:
|
196
|
+
case yajl_tok_null:
|
197
197
|
if (hand->callbacks && hand->callbacks->yajl_null) {
|
198
198
|
_CC_CHK(hand->callbacks->yajl_null(hand->ctx));
|
199
199
|
}
|
@@ -287,13 +287,13 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
287
287
|
_CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
|
288
288
|
}
|
289
289
|
yajl_bs_pop(hand->stateStack);
|
290
|
-
goto around_again;
|
290
|
+
goto around_again;
|
291
291
|
}
|
292
292
|
/* intentional fall-through */
|
293
293
|
}
|
294
|
-
case yajl_tok_colon:
|
295
|
-
case yajl_tok_comma:
|
296
|
-
case yajl_tok_right_bracket:
|
294
|
+
case yajl_tok_colon:
|
295
|
+
case yajl_tok_comma:
|
296
|
+
case yajl_tok_right_bracket:
|
297
297
|
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
298
298
|
hand->parseError =
|
299
299
|
"unallowed token at this point in JSON text";
|
@@ -312,7 +312,7 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
312
312
|
yajl_reset_parser(hand);
|
313
313
|
} else if (s == yajl_state_map_need_val) {
|
314
314
|
yajl_bs_set(hand->stateStack, yajl_state_map_got_val);
|
315
|
-
} else {
|
315
|
+
} else {
|
316
316
|
yajl_bs_set(hand->stateStack, yajl_state_array_got_val);
|
317
317
|
}
|
318
318
|
}
|
@@ -322,7 +322,7 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
322
322
|
|
323
323
|
goto around_again;
|
324
324
|
}
|
325
|
-
case yajl_state_map_start:
|
325
|
+
case yajl_state_map_start:
|
326
326
|
case yajl_state_map_need_key: {
|
327
327
|
/* only difference between these two states is that in
|
328
328
|
* start '}' is valid, whereas in need_key, we've parsed
|
@@ -358,12 +358,12 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
358
358
|
_CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
|
359
359
|
}
|
360
360
|
yajl_bs_pop(hand->stateStack);
|
361
|
-
goto around_again;
|
361
|
+
goto around_again;
|
362
362
|
}
|
363
363
|
default:
|
364
364
|
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
365
365
|
hand->parseError =
|
366
|
-
"invalid object key (must be a string)";
|
366
|
+
"invalid object key (must be a string)";
|
367
367
|
goto around_again;
|
368
368
|
}
|
369
369
|
}
|
@@ -373,7 +373,7 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
373
373
|
switch (tok) {
|
374
374
|
case yajl_tok_colon:
|
375
375
|
yajl_bs_set(hand->stateStack, yajl_state_map_need_val);
|
376
|
-
goto around_again;
|
376
|
+
goto around_again;
|
377
377
|
case yajl_tok_eof:
|
378
378
|
return yajl_status_insufficient_data;
|
379
379
|
case yajl_tok_error:
|
@@ -395,10 +395,10 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
395
395
|
_CC_CHK(hand->callbacks->yajl_end_map(hand->ctx));
|
396
396
|
}
|
397
397
|
yajl_bs_pop(hand->stateStack);
|
398
|
-
goto around_again;
|
398
|
+
goto around_again;
|
399
399
|
case yajl_tok_comma:
|
400
400
|
yajl_bs_set(hand->stateStack, yajl_state_map_need_key);
|
401
|
-
goto around_again;
|
401
|
+
goto around_again;
|
402
402
|
case yajl_tok_eof:
|
403
403
|
return yajl_status_insufficient_data;
|
404
404
|
case yajl_tok_error:
|
@@ -406,8 +406,8 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
406
406
|
goto around_again;
|
407
407
|
default:
|
408
408
|
yajl_bs_set(hand->stateStack, yajl_state_parse_error);
|
409
|
-
hand->parseError = "after key and value, inside map, "
|
410
|
-
"I expect ',' or '}'";
|
409
|
+
hand->parseError = "after key and value, inside map, "
|
410
|
+
"I expect ',' or '}'";
|
411
411
|
/* try to restore error offset */
|
412
412
|
if (*offset >= bufLen) *offset -= bufLen;
|
413
413
|
else *offset = 0;
|
@@ -423,10 +423,10 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
423
423
|
_CC_CHK(hand->callbacks->yajl_end_array(hand->ctx));
|
424
424
|
}
|
425
425
|
yajl_bs_pop(hand->stateStack);
|
426
|
-
goto around_again;
|
426
|
+
goto around_again;
|
427
427
|
case yajl_tok_comma:
|
428
428
|
yajl_bs_set(hand->stateStack, yajl_state_array_need_val);
|
429
|
-
goto around_again;
|
429
|
+
goto around_again;
|
430
430
|
case yajl_tok_eof:
|
431
431
|
return yajl_status_insufficient_data;
|
432
432
|
case yajl_tok_error:
|
@@ -440,7 +440,7 @@ yajl_do_parse(yajl_handle hand, unsigned int * offset,
|
|
440
440
|
}
|
441
441
|
}
|
442
442
|
}
|
443
|
-
|
443
|
+
|
444
444
|
abort();
|
445
445
|
return yajl_status_error;
|
446
446
|
}
|
data/ext/yajl_parser.h
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright 2007-2009, Lloyd Hilaiel.
|
3
|
-
*
|
3
|
+
*
|
4
4
|
* Redistribution and use in source and binary forms, with or without
|
5
5
|
* modification, are permitted provided that the following conditions are
|
6
6
|
* met:
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* 1. Redistributions of source code must retain the above copyright
|
9
9
|
* notice, this list of conditions and the following disclaimer.
|
10
|
-
*
|
10
|
+
*
|
11
11
|
* 2. Redistributions in binary form must reproduce the above copyright
|
12
12
|
* notice, this list of conditions and the following disclaimer in
|
13
13
|
* the documentation and/or other materials provided with the
|
14
14
|
* distribution.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* 3. Neither the name of Lloyd Hilaiel nor the names of its
|
17
17
|
* contributors may be used to endorse or promote products derived
|
18
18
|
* from this software without specific prior written permission.
|
19
|
-
*
|
19
|
+
*
|
20
20
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
21
21
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
22
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
@@ -28,7 +28,7 @@
|
|
28
28
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
29
29
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
30
|
* POSSIBILITY OF SUCH DAMAGE.
|
31
|
-
*/
|
31
|
+
*/
|
32
32
|
|
33
33
|
#ifndef __YAJL_PARSER_H__
|
34
34
|
#define __YAJL_PARSER_H__
|
@@ -44,7 +44,7 @@ typedef enum {
|
|
44
44
|
yajl_state_parse_error,
|
45
45
|
yajl_state_lexical_error,
|
46
46
|
yajl_state_map_start,
|
47
|
-
yajl_state_map_sep,
|
47
|
+
yajl_state_map_sep,
|
48
48
|
yajl_state_map_need_val,
|
49
49
|
yajl_state_map_got_val,
|
50
50
|
yajl_state_map_need_key,
|
data/lib/yajl.rb
CHANGED
@@ -13,18 +13,18 @@ require 'yajl_ext'
|
|
13
13
|
#
|
14
14
|
# Ruby bindings to the excellent Yajl (Yet Another JSON Parser) ANSI C library.
|
15
15
|
module Yajl
|
16
|
-
VERSION = "0.7.
|
17
|
-
|
16
|
+
VERSION = "0.7.2"
|
17
|
+
|
18
18
|
# For compatibility, has the same signature of Yajl::Parser.parse
|
19
19
|
def self.load(str_or_io, options={}, read_bufsize=nil, &block)
|
20
20
|
Parser.parse(str_or_io, options, read_bufsize, &block)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# For compatibility, has the same signature of Yajl::Encoder.encode
|
24
24
|
def self.dump(obj, *args, &block)
|
25
25
|
Encoder.encode(obj, args, &block)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
class Parser
|
29
29
|
# A helper method for parse-and-forget use-cases
|
30
30
|
#
|
@@ -39,7 +39,7 @@ module Yajl
|
|
39
39
|
new(options).parse(str_or_io, read_bufsize, &block)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
class Encoder
|
44
44
|
# A helper method for encode-and-forget use-cases
|
45
45
|
#
|
@@ -75,7 +75,7 @@ module Yajl
|
|
75
75
|
new(options).encode(obj, io, &block)
|
76
76
|
end
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# DEPRECATED - See Yajl::Parser and Yajl::Encoder
|
80
80
|
module Stream
|
81
81
|
# DEPRECATED - See Yajl::Parser
|
@@ -83,7 +83,7 @@ module Yajl
|
|
83
83
|
warn "WARNING: Yajl::Stream has be deprecated and will most likely be gone in the next release. Use the Yajl::Parser class instead."
|
84
84
|
Parser.new.parse(str_or_io)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
# DEPRECATED - See Yajl::Encoder
|
88
88
|
def self.encode(obj, str_or_io=nil)
|
89
89
|
warn "WARNING: Yajl::Stream has be deprecated and will most likely be gone in the next release. Use the Yajl::Encoder class instead."
|
@@ -4,16 +4,6 @@ module Yajl
|
|
4
4
|
# This is a wrapper around Bzip::Reader to allow it's #read method to adhere
|
5
5
|
# to the IO spec, allowing for two parameters (length, and buffer)
|
6
6
|
class StreamReader < ::Bzip2::Reader
|
7
|
-
|
8
|
-
# A helper method to allow use similar to IO#read
|
9
|
-
def read(len=nil, buffer=nil)
|
10
|
-
unless buffer.nil?
|
11
|
-
buffer.replace super(len)
|
12
|
-
return buffer
|
13
|
-
end
|
14
|
-
super(len)
|
15
|
-
end
|
16
|
-
|
17
7
|
# Helper method for one-off parsing from a bzip2-compressed stream
|
18
8
|
#
|
19
9
|
# See Yajl::Parser#parse for parameter documentation
|
@@ -21,7 +11,7 @@ module Yajl
|
|
21
11
|
if input.is_a?(String)
|
22
12
|
input = StringIO.new(input)
|
23
13
|
end
|
24
|
-
|
14
|
+
|
25
15
|
Yajl::Parser.new(options).parse(new(input), buffer_size, &block)
|
26
16
|
end
|
27
17
|
end
|
@@ -3,7 +3,7 @@ module Yajl
|
|
3
3
|
module Bzip2
|
4
4
|
# A wrapper around the Bzip2::Writer class for easier JSON stream encoding
|
5
5
|
class StreamWriter < ::Bzip2::Writer
|
6
|
-
|
6
|
+
|
7
7
|
# A helper method for encoding to a bzip2-compressed stream
|
8
8
|
#
|
9
9
|
# Look up Yajl::Encoder#encode for parameter documentation
|
@@ -4,20 +4,19 @@ module Yajl
|
|
4
4
|
# This is a wrapper around Zlib::Inflate, creating a #read method that adheres
|
5
5
|
# to the IO spec, allowing for two parameters (length, and buffer)
|
6
6
|
class StreamReader < ::Zlib::Inflate
|
7
|
-
|
7
|
+
|
8
8
|
# Wrapper to the initialize method so we can set the initial IO to parse from.
|
9
9
|
def initialize(io, options)
|
10
10
|
@io = io
|
11
11
|
super(options)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# A helper method to allow use similar to IO#read
|
15
|
-
def read(len=nil
|
16
|
-
|
15
|
+
def read(len=nil)
|
16
|
+
return nil if finished? or ended?
|
17
17
|
inflate(@io.read(len))
|
18
18
|
end
|
19
|
-
|
20
|
-
|
19
|
+
|
21
20
|
# Helper method for one-off parsing from a deflate-compressed stream
|
22
21
|
#
|
23
22
|
# See Yajl::Parser#parse for parameter documentation
|
@@ -25,7 +24,7 @@ module Yajl
|
|
25
24
|
if input.is_a?(String)
|
26
25
|
input = StringIO.new(input)
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
if options.is_a?(Hash)
|
30
29
|
deflate_options = options.delete(:deflate_options)
|
31
30
|
Yajl::Parser.new(options).parse(new(input, deflate_options), buffer_size, &block)
|