• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    Julia
  • License
    Other
  • Created almost 7 years ago
  • Updated 10 months ago

Reviews

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

Repository Details

BSON

CI

BSON.jl is a Julia package for working with the Binary JSON serialisation format. It can be used as a general store for Julia data structures, with the following features:

  • Lightweight and ubiquitous, with a simple JSON-like data model and clients in many languages.
  • Efficient for binary data (eg. arrays of floats).
  • Flexible enough to handle anything you throw at it – closures, custom types, circular data structures, etc.
  • Backwards compatible, so that if data layout changes old files will still load.
julia> using BSON

julia> bson("test.bson", Dict(:a => [1+2im, 3+4im], :b => "Hello, World!"))

julia> BSON.load("test.bson")
Dict{Symbol,Any} with 2 entries:
  :a => Complex{Int64}[1+2im, 3+4im]
  :b => "Hello, World!"

(Note that the top-level object in BSON is always a Dict{Symbol,Any}).

⚠️ Warning: Loading BSON files is not safe from malicious or erroneously constructed data. Loading BSON files can cause arbitrary code to execute on your machine. Do not load files from unknown or untrusted sources.

There a few utility methods for working with BSON files.

julia> using BSON

julia> bson("test.bson", a = 1, b = 2)

julia> BSON.load("test.bson")
Dict{Symbol,Any} with 2 entries:
  :a => 1
  :b => 2

julia> using BSON: @save, @load

julia> a, b = 1, 2
(1, 2)

julia> @save "test.bson" a b # Same as above

julia> @load "test.bson" a b # Loads `a` and `b` back into the workspace

For external files you can use BSON.parse to load raw BSON data structures without any Julia-specific interpretation. In basic cases, this will look that same, but Julia-specific types will be stored in a more complex format.

julia> BSON.parse("test.bson")
Dict{Symbol,Any} with 2 entries:
  :a => 1
  :b => 2

julia> BSON.parse("test.bson")[:data]
Dict{Symbol,Any} with 4 entries:
  :tag  => "array"
  :type => Dict(:tag=>"datatype",:params=>Any[],:name=>["Core","Int64"])
  :size => [3]
  :data => UInt8[0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00  …  ]

This is also how the data will appear to readers in other languages, should you wish to move data outside of Julia.

Notes

Below is some semi-official documentation on more advanced usage.

Loading custom data types within modules

For packages that use BSON.jl to load data, just writing BSON.load("mydata.bson") will not work with custom data types. Here's a simple example of that for DataFrames.jl:

module A
  using DataFrames, BSON
  d = DataFrame(a = 1:10, b = 5:14)
  bson("data.bson", Dict(:d=>d))
  d2 = BSON.load("data.bson") # this will throw an error
end

In these cases, you can specify the namespace under which to resolve types like so:

d2 = BSON.load("data.bson", @__MODULE__)

This will use the current module's namespace when loading the data. You could also pass any module name as the second argument (though almost all cases will use @__MODULE__). By default, the namespace is Main (i.e. the REPL).

More Repositories

1

JLD2.jl

HDF5-compatible file format in pure Julia
Julia
553
star
2

HDF5.jl

Save and load data in the HDF5 file format from Julia
Julia
390
star
3

JSON.jl

JSON parsing and printing
Julia
312
star
4

MAT.jl

Julia module for reading MATLAB files
Julia
279
star
5

JLD.jl

Saving and loading julia variables while preserving native types
Julia
276
star
6

FileIO.jl

Main Package for IO, loading all different kind of files
Julia
217
star
7

ProtoBuf.jl

Julia protobuf implementation
Julia
205
star
8

Formatting.jl

Deprecated. See README. (A Julia package to provide Python-like formatting support)
Julia
131
star
9

VideoIO.jl

Reading and writing of video files in Julia via ffmpeg
Julia
128
star
10

Suppressor.jl

Julia macros for suppressing and/or capturing output (STDOUT), warnings (STDERR) or both streams at the same time.
Julia
124
star
11

EzXML.jl

XML/HTML handling tools for primates
Julia
122
star
12

Zarr.jl

Julia
119
star
13

Parquet.jl

Julia implementation of Parquet columnar file format reader
Julia
116
star
14

LightXML.jl

A light-weight Julia package for XML based on libxml2.
Julia
91
star
15

TranscodingStreams.jl

Simple, consistent interfaces for any codec.
Julia
86
star
16

MeshIO.jl

IO for Meshes
Roff
79
star
17

Tar.jl

TAR files: create, list, extract them in pure Julia
Julia
79
star
18

MsgPack.jl

Julia MsgPack implementation with type-driven, overloadable packing/unpacking functionality
Julia
65
star
19

LibSerialPort.jl

Julia wrapper for the libserialport c library
Julia
65
star
20

ImageMagick.jl

Thin Wrapper for the library ImageMagick
Julia
53
star
21

CodecZlib.jl

zlib codecs for TranscodingStreams.jl.
Julia
52
star
22

ConfParser.jl

Julia package for parsing configuration files
Julia
43
star
23

BufferedStreams.jl

Fast composable IO streams
Julia
42
star
24

Sixel.jl

The Julia wrapper of libsixel
Julia
41
star
25

GZip.jl

A Julia interface for gzip functions in zlib
Julia
39
star
26

FFMPEG.jl

Julia Package for the FFMPEG builder binaries
Julia
34
star
27

SerialPorts.jl

SerialPort IO streams in Julia backed by pySerial.
Julia
31
star
28

Blosc.jl

Blosc compression for the Julia language
Julia
29
star
29

ImageIO.jl

Load images in Julia. Designed for FileIO interaction. Supports PNG and Portable Bitmap formats
Julia
28
star
30

GoogleDrive.jl

Automate Google-Drive download in Julia
Julia
24
star
31

MultifileArrays.jl

Create a higher-dimensional array from lazily-loaded slices in separate files
Julia
23
star
32

CodecZstd.jl

A zstd codec for TranscodingStreams.jl.
Julia
23
star
33

StructIO.jl

binary I/O methods generated from Julia structure definitions
Julia
22
star
34

Pcap.jl

libpcap implementation for Julia language
Julia
20
star
35

PNGFiles.jl

FileIO.jl integration for PNG files
Julia
20
star
36

CBOR.jl

A Concise Binary Object Representation (RFC 7049) serialization library in Julia
Julia
19
star
37

FileTypes.jl

Small and dependency-free Julia package to infer file and MIME type checking the magic numbers signature.
Julia
18
star
38

Snappy.jl

A fast compressor/decompressor
Julia
16
star
39

JpegTurbo.jl

Julia interface to libjpeg-turbo
Julia
15
star
40

ArgTools.jl

Tools for writing functions that handle many kinds of IO arguments
Julia
14
star
41

IniFile.jl

Reading and writing Windows-style INI files (writing not yet implemented).
Julia
14
star
42

ZipArchives.jl

Read and write Zip archive files in Julia.
Julia
13
star
43

HexEdit.jl

Julia package for editing and displaying binary file data in hexadecimal format
Julia
13
star
44

WidthLimitedIO.jl

A Julia IO type that facilitates width-limited printing
Julia
12
star
45

QuartzImageIO.jl

Exposes macOS's native image IO functionality to Julia
Julia
12
star
46

GIFImages.jl

Provides Gif support in Julia using LibGif
Julia
12
star
47

NRRD.jl

Julia support for the Nearly Raw Raster Data (NRRD) image file format
Julia
10
star
48

ZeissMicroscopyFormat.jl

Importing the Zeiss CZI file format for microscopy
Julia
9
star
49

LibExpat.jl

Julia interface to the Expat XML parser library
Julia
9
star
50

CodecLz4.jl

Transcoding codecs for compression and decompression with LZ4
Julia
9
star
51

FLAC.jl

Julia bindings for libFLAC
Julia
9
star
52

CodecBzip2.jl

A bzip2 codec for TranscodingStreams.jl.
Julia
8
star
53

ImgHdr.jl

Library to Check Type of Image
Julia
7
star
54

CodecXz.jl

An xz codec for TranscodingStreams.jl.
Julia
7
star
55

CodecBase.jl

Base 16/32/64 codecs for TranscodingStreams.jl
Julia
7
star
56

CRC32.jl

CRC32 package for Julia
Julia
6
star
57

Telegram.jl

wrapper for the Telegram API in Julia (https://github.com/vysheng/tgl)
Julia
6
star
58

Toxcore.jl

Toxcore wrapper
Julia
6
star
59

VideoPlayer.jl

Video player for Julia
Julia
6
star
60

BSDiff.jl

Pure Julia port of bsdiff
Julia
5
star
61

HDF5Plugins.jl

Compression plugins for HDF5.jl implemented in Julia
Julia
5
star
62

libserialport

A mirror of libserialport for the provision of Windows binaries through CI
C
5
star
63

MetaImageFormat.jl

Support for reading MetaImage files in Julia
Julia
4
star
64

AndorSIF.jl

Read Andor SIF file in Julia
Julia
4
star
65

AdjustCRC.jl

adjust the CRC32/32c checksum of data to any desired value
Julia
4
star
66

Netpbm.jl

Load and save Netpbm images in Julia
Julia
4
star
67

ImageMagickBuilder

binary deps for ImageMagick
Julia
3
star
68

Blosc2.jl

blosc2 wrapper for Julia lang
Julia
3
star
69

SigMF.jl

The Signal Metadata Format
Julia
3
star
70

AVSfldIO.jl

File IO for AVS .fld format data files
Julia
2
star
71

BSDiffTestData

Data for testing https://github.com/JuliaIO/BSDiff.jl
2
star
72

LibpngBuilder

Julia
2
star
73

FFMPEGBuilder

BinaryBuilder repo for FFMPEG
Julia
2
star
74

LibVPXBuilder

BinaryBuilder repo for LibVPX
Julia
2
star
75

x264Builder

BinaryBuilder repo for x264
Julia
2
star
76

YasmBuilder

BinaryBuilder repo for Yasm
Julia
2
star
77

LibJPEGBuilder

Julia
2
star
78

LibTIFFBuilder

Julia
2
star
79

LAMEBuilder

Julia
2
star
80

WavefrontObj.jl

Julia
2
star
81

nasmBuilder

Julia
2
star
82

LibVorbisBuilder

builder for libvorbis
Julia
2
star
83

JLDArchives.jl

A repository of Julia *.jld files for testing backwards compatibility
Julia
2
star
84

OggBuilder

BinaryBuilder repo for libogg
Julia
2
star
85

x265Builder

BinaryBuilder repo for x265
Julia
2
star
86

LibassBuilder

Julia
2
star
87

LibALSABuilder

BinaryBuilder repo for alsa-lib
Julia
2
star
88

InputBuffers.jl

A Julia package to wrap an AbstractVector{UInt8} in a readable seekable IO type.
Julia
2
star
89

Roadmap

Roadmap for the JuliaIO Organization
2
star
90

CodecInflate64.jl

Julia implementation of deflate64 decompression
Julia
1
star
91

Kerchunk.jl

Julia
1
star