Code Monkey home page Code Monkey logo

base85's Introduction

base85

Base85 encoder/decoder written in native Dart.

Where base64 adds approximately 1/3, base85 only adds about 1/4. Of course there's a tradeoff. The Base85 alphabet includes characters that might not be as friendly as the base64 alphabet. While it's still only printable characters, the Ascii85 specification contains quotes (' and ") which needs escaping in many programming languages, and the ZeroMQ specification contains < and > which need escaping in most (all?) SGML languages.

IPv6 encoding should only be used for encoding IPv6 addresses. When using IPv6, input for encoding must always be 16 bytes, and input for decoding must always be 20 bytes.

ZeroMQ's version (z85) require according to the specification) string input to be divisible by 5, and binary input to be divisible by 4.

Supported encoding specifications

Example

Base85

import 'dart:io';
import 'dart:typed_data';

import 'package:base85/base85.dart';

void main() {
  var codec = Base85Codec(Alphabets.z85);
  var encode = codec.encode(Uint8List.fromList('Hello, world!!!!'.codeUnits));
  print(encode);

  /// =>   nm=QNz.92Pz/PV8aT50L
  print(String.fromCharCodes(codec.decode(encode)));

  /// =>   Hello, world!!!!

  codec = Base85Codec(Alphabets.ascii85, AlgoType.ascii85);
  print(codec.encode(Uint8List.fromList('Hello, world'.codeUnits)));

  /// =>    <~87cURD_*#TDfTZ)~>
  print(String.fromCharCodes(codec.decode('<~87cURD_*#TDfTZ)~>')));

  /// =>    Hello, world

  codec = Base85Codec(Alphabets.IPv6, AlgoType.IPv6);
  var address = InternetAddress(
    '1080::8:800:200c:417a',
    type: InternetAddressType.IPv6,
  );
  print(codec.encode(address.rawAddress));

  /// =>    4)+k&C#VzJ4br>0wv%Yp
  ///
  var decode = codec.decode('4)+k&C#VzJ4br>0wv%Yp');
  address = InternetAddress.fromRawAddress(
    decode,
    type: InternetAddressType.IPv6,
  );
  print(address.address);

  /// =>    1080::8:800:200c:417a
}

base85's People

Contributors

lucke0051 avatar litaoh avatar

Stargazers

Isaque Neves avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

base85's Issues

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.