File: chunked_encoding.rb

package info (click to toggle)
ruby-yajl 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,980 kB
  • sloc: ansic: 2,473; ruby: 2,049; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 842 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../lib')

require 'yajl'

obj = {
  :a_test => "of encoding in one pass" * 512,
  :a_test2 => "of encoding in one pass" * 512,
  :a_test3 => "of encoding in one pass" * 512,
  :a_test4 => "of encoding in one pass" * 512,
  :which_will => "simply return a string when finished" * 512,
  :which_will2 => "simply return a string when finished" * 512,
  :which_will3 => "simply return a string when finished" * 512,
  :which_will4 => "simply return a string when finished" * 512,
  :as_easy_as => 123
}

chunks = 0
total_size = 0

Yajl::Encoder.encode(obj) do |chunk|
  chunks += 1
  total_size += chunk.size
  STDOUT << chunk
end

puts "\n\nEncoder generated #{total_size} bytes of data, in #{chunks} chunks"