GithubHelp home page GithubHelp logo

writema's Introduction

Writema? What's Writema?

Writema is a binary stream writing library

Well, what does it do?

Well I'm glad you asked!

Writema is a little library I started to help with writing binary files.

That's it?

Well yeah, what did you expect? Some large module I've been writing my entire life that will change the world with its amazing binary writing ability?

Cool Badges

Tests

Usage

Note, requires Python 3.8 or higher (For now at least)

Installation

pip install writema

Sample code

from writema import Writema

# Let's say you want to write a file to contain in order:
# - An integer
# - An unsigned integer
# - A double
# - A string prefixed by its length with a byte
# - A large buffer blob you dont exactly know the length of
w = Writema("some_file.bin") # note: defaults to Little Endian

w.write(4, 69)  # write a 4 byte integer (int32_t)
w.uwrite(2, -1337)  # write an unsigned 2 bit integer (uint16_t)

w.write("d", 2.718281828459045)  # write the constant e as a double

string = b"Hello, World!"
length = len(string)

w.write(1, length)
w.bytes(string)

important_data = ...  # imagine theres some very large binary blob here in bytes
w.bytes(important_data)

Example of ways to do the same action

from writema import Writema, WritemaTypes

w = Writema()

# lets say you want the end buffer to be b"AAAABBBBCCCCDDDD"
# heres four ways you can do each of the four bytes

w.write(4, 1094795585)  # Writes a 32 bit (4 byte) integer (AAAA = 1094795585)
w.write("int", 1111638594)  # this also writes a 32 bit int (BBBB = 1111638594)
w.write(WritemaTypes.int, 1128481603)  # someone might prefer this idk (CCCC = 1128481603)
w.bytes(b"DDDD")  # its a bytestring, probably the easiest to work with

Other examples

# writing floats and doubles is a little scuffed for now, i plan to find a better solution
w.write("f", 6.9)
w.write("float", 6.9)
w.write(WritemaTypes.float, 6.9)
w.write("d", 6.90000001)
w.write("double", 6.90000001)
w.write(WritemaTypes.double, 6.90000001)

# you can also set endianness
w.set_endianness("big")
# and
w.set_endianness("little")  # the correct endianness /s

Documentation

License

Copyright (c) 2022 whamer100
This project is MIT licensed.


hey is this project name just one big ligma joke

maybe

writema's People

Contributors

whamer100 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.