Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arcage/crystal-quotedprintable
Quoted-printable handling module for Crystal
https://github.com/arcage/crystal-quotedprintable
crystal quoted-printable
Last synced: 24 days ago
JSON representation
Quoted-printable handling module for Crystal
- Host: GitHub
- URL: https://github.com/arcage/crystal-quotedprintable
- Owner: arcage
- License: mit
- Created: 2017-08-13T02:57:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T23:24:04.000Z (over 3 years ago)
- Last Synced: 2024-10-25T01:36:41.913Z (2 months ago)
- Topics: crystal, quoted-printable
- Language: Crystal
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Quoted Printable for Crystal
The `QuotedPrintable` module provides for the encoding (`#encode`) and decoding (`#decode`, `#decode_string`) of binary data using a base64 representation.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
quoted_printable:
github: arcage/crystal-quotedprintable
```## Usage
```crystal
require "quoted_printable"data = <<-HTM
日本語タイトル
見出し
本文
HTM
encoded = QuotedPrintable.encode(data)
# =>
#
# =E6=97=A5=E6=9C=AC=E8=AA=9E=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB
#
#
#=E8=A6=8B=E5=87=BA=E3=81=97
#=E6=9C=AC=E6=96=87
#
#decoded = QuotedPrintable.decode_string(encoded)
#=>
#
# 日本語タイトル
#
#
#見出し
#本文
#
#
```An argument of the `#encode` can be `String` or `Enumerable(UInt8)`(eg. `Bytes`, `Array(UInt8)`, `Tuple(UInt8)`) .
When the `String` object is given, it will be encoded as a text. That means it will be encoded with literal representation, and all line breaks in it will be represented as a CRLF sequence.
When the `Enumerable(UInt8)` object is given, all bytes wil be encoded as it is.
In case of the encoding as a text, even if original data was written with LF line breaks, all line breaks in decoded data will be CRLF. To avoid this, you can specify the line break code with `line_break:` argument of `#decode_string` method.
```crystal
# decode with LF line breaks
decoded = QuotedPrintable.decode_string(encoded, line_break: "\n")
```To decode non-utf-8 text, you can specify the `encoding:` and `invalid:` arguments, same as those of the some methods of `String`.
```crystal
# decode from Shift JIS text
decoded = QuotedPrintable.decode_string(encoded, encoding: "Shift_JIS", invalid: :skip)
```## Contributors
- [ʕ·ᴥ·ʔAKJ](https://github.com/arcage) - creator, maintainer