crystal-community / crystal-libraries-needed

A list of libraries that are needed or wanted for the Crystal-Language
141 stars 4 forks source link

Implementation of Array#pack and String#unpack methods from Ruby language #82

Closed mamantoha closed 6 years ago

Papierkorb commented 6 years ago

That API isn't really a good fit for Crystal. Strings are not for binary data, and Array isn't a suitable container for such "unpacked" data.

A sane API, maybe using the mapping pattern, would be much much better, safe and actually usable.

RX14 commented 6 years ago

Sorry, there are technical reasons we can't implement those APIs, on top of design reasons why we don't want to implement them anyway.

As @Papierkorb said, IO is typically how you want to represent binary data waiting to be decoded, then you can use IO#read_bytes and IO#write_bytes to replace most usecases of unpack and pack respectively.

Please drop by gitter or the mailing list if you need help with a specific example.