• Stars
    star
    24
  • Rank 954,194 (Top 20 %)
  • Language
    Crystal
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BSON implementation written in Crystal

BSON

BSON implemented in Crystal according to the spec.

Installation

Add this line to your application's shard.yml:

dependencies:
  bson:
    github: jeromegn/bson.cr

Usage

require "bson"

io = File.open(File.expand_path("examples/sample.bson")) # A pretty representative BSON document
BSON.decode(io) # => Returns a Hash instance

bson, writer = IO.pipe
"a string".to_bson(writer) # => encodes the string to BSON and writes to the IO

puts String.from_bson(bson).inspect # => "a string"

doc = Hash{
  "name" => "hello",
  "int" => 32
}

puts doc # => { "name" => "hello", "int" => 32 }

bson, writer = IO.pipe
doc.to_bson(writer) # => Encodes the whole document to BSON and writes to the IO

puts BSON.decode(bson) # => { "name" => "hello", "int" => 32 }

Supported types

All types specified in the BSON spec.

Relevant basic types of Crystal have been extended to add #to_bson(io : IO) and .from_bson(io : IO) for simplicity.

A BSON::Document is just an alias for Hash(String, BSON::Type)

TODOs

  • More tests

Caveats

  • Only supported Regex options are the ones also supported by Crystal: i and m basically.

Contributing

  1. Fork it ( https://github.com/jeromegn/bson.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • jeromegn Jerome Gravel-Niquet - creator, maintainer

More Repositories

1

Backbone.localStorage

A localStorage adapter for Backbone.js
JavaScript
1,899
star
2

DocumentUp

Pretty documentation generator for Github projects with proper Readme.
Ruby
886
star
3

slang

Slim-inspired templating language for Crystal
Crystal
232
star
4

kilt

Generic template interface for Crystal
Crystal
148
star
5

localtodos

Simple Todos App built on Backbone.js
JavaScript
99
star
6

protobuf.cr

Protobuf generator, encoder and decoder.
Crystal
95
star
7

poutine

MongoDB ORM for Node.js
CoffeeScript
35
star
8

docker.cr

Docker API client in Crystal.
Crystal
26
star
9

influxdb.cr

InfluxDB driver for Crystal
Crystal
25
star
10

v8.cr

V8 bindings for Crystal
C++
16
star
11

dry-types-rails

Dry::Types railties
Ruby
11
star
12

beautifier

A safari extension which smooths fonts!
10
star
13

Warping-Shadow-CSS3

Warping Shadows can be done in CSS3
Ruby
8
star
14

mongol

Light modeling for MongoDB.
JavaScript
8
star
15

jeromegn.github.com

Personal site
HTML
5
star
16

rapid

Redis ORM-ish api for nodejs
JavaScript
3
star
17

backbone.pjax

Backbone utilities for web apps using PJAX.
JavaScript
3
star
18

rhai-tpl

Simple template engine using rhai for logic
Rust
2
star
19

qml.cr

QML library for Crystal
Crystal
2
star
20

quinn-plaintext

QUIC pluggable crypto to use the protocol as plaintext (for use when cryptography is already handled at another layer, e.g. Wireguard)
Rust
1
star
21

Radiophonique

Objective-C
1
star
22

containerd-rs

Rust
1
star
23

lg-ultrafine-brightness

Control LG Ultrafine brightness on linux
Rust
1
star
24

documentup.js

experimental DocumentUp running on fly.io
JavaScript
1
star
25

portfolio

My portfolio, built with StaticMatic
JavaScript
1
star
26

node-api-boilerplate

Simple Node.js API server boilerplate using CoffeeScript and Express
CoffeeScript
1
star