3 ms·
Here's an implementation of ASCII Delimited Text in Ruby using the standard csv library: https://gist.github.com/christiangenco/73a7cfdb03e381bff2e9 https://gis
by christiangenco 13y ago
Here's an implementation of ASCII Delimited Text in Ruby using the standard csv library: https://gist.github.com/christiangenco/73a7cfdb03e381bff2e9 https://gist.github.com/christiangenco/73a7cfdb03e381bff2e9
The only trouble I ran into was that the library doesn't like getting rid of your quote character[1], and I don't see an easy way around it[2].
That said, I really don't like this format. The entire point of CSV is that you have a serialization of an object list that can be edited by hand. Sure using weird ASCII characters compresses it a bit because you're not putting quotes around everything, but if you're worried about compression you should be using another form of serialization - perhaps just gzip your csv or json.
In Ruby in particular, we have this wonderful module called Marshal[3] that serializes objects to and from bytes with the super handy:
serialized = Marshal.dump(data)
deserialized = Marshal.load(serialized)
deserialized == data # returns true
I cannot think of a single reason to use ASCII Delimited Text over Marshal serialization or CSV.
1. ruby/1.9.1/csv.rb:2028:in `init_separators': :quote_char has to be a single character String (ArgumentError)
2. http://rxr.whitequark.org/mri/source/lib/csv.rb http://rxr.whitequark.org/mri/source/lib/csv.rb
3. http://www.ruby-doc.org/core-2.1.1/Marshal.html http://www.ruby-doc.org/core-2.1.1/Marshal.html