Idris Brhane

Idris Brhane

1612613400

JPEG Encoder/Decoder for Deno

JPEG

JPEG Encoder/Decoder for Deno based on Node’s jpeg-js.

Example

Decode JPEG

import JPEG from "https://deno.land/x/jpeg/mod.ts";

const img = await Deno.readFile("./img.jpg");
const raw = JPEG.decode(img);

console.log(raw);

/*
{
  width: 850,
  height: 571,
  exifBuffer: undefined,
  data: Buffer(1941400) [
     78,  73,  83, 255,  86,  81,  91, 255,  82,  77,  85, 255,  68,  63,  71,
    255,  61,  56,  64, 255,  67,  62,  70, 255,  73,  68,  76, 255,  71,  66,
     74, 255,  65,  60,  66, 255,  75,  70,  76, 255,  83,  78,  84, 255,  81,
     76,  82, 255,  75,  71,  74, 255,  79,  75,  78, 255,  96,  92,  95, 255,
    113, 109, 112, 255,  95,  92,  99, 255,  86,  83,  90, 255,  89,  86,  93,
    255,  91,  88,  95, 255,  74,  71,  78, 255,  57,  54,  61, 255,  65,  62,
     69, 255,  83,  80,  87, 255,  83,  80,  87, 255,
    ... 1941300 more items
  ]
}
*/

Encoding JPEG

import JPEG from "https://deno.land/x/jpeg/mod.ts";

const width = 320, height = 180;
const frameData = new Uint8Array(width * height * 4);

let i = 0;
while(i < frameData.length) {
    frameData[i++] = 255; // red
    frameData[i++] = 66; // green
    frameData[i++] = 159; // blue
    frameData[i++] = 0; // alpha - ignored in JPEGs
}

const rawImageData = {
    data: frameData,
    width: width,
    height: height,
};
var jpegImageData = JPEG.encode(rawImageData, 50);
console.log(jpegImageData);

Deno.writeFileSync("./test/enc.jpg", jpegImageData.data);

/*
{
  data: Uint8Array(2222) [
    255, 216, 255, 224,  0,  16,  74,  70,  73,  70,   0,   1,   1,  0,  0,
      1,   0,   1,   0,  0, 255, 219,   0, 132,   0,  16,  11,  12, 14, 12,
     10,  16,  14,  13, 14,  18,  17,  16,  19,  24,  40,  26,  24, 22, 22,
     24,  49,  35,  37, 29,  40,  58,  51,  61,  60,  57,  51,  56, 55, 64,
     72,  92,  78,  64, 68,  87,  69,  55,  56,  80, 109,  81,  87, 95, 98,
    103, 104, 103,  62, 77, 113, 121, 112, 100, 120,  92, 101, 103, 99,  1,
     17,  18,  18,  24, 21,  24,  47,  26,  26,  47,
    ... 2122 more items
  ],
  width: 320,
  height: 180
}
*/

Options

Decode Options

Option Description Default
colorTransform Transform alternate colorspaces like YCbCr. undefined means respect the default behavior encoded in metadata. undefined
useTArray Decode pixels into a typed Uint8Array instead of a Buffer. false
formatAsRGBA Decode pixels into RGBA vs. RGB. true
tolerantDecoding Be more tolerant when encountering technically invalid JPEGs. true
maxResolutionInMP The maximum resolution image that jpeg should attempt to decode in megapixels. Images larger than this resolution will throw an error instead of decoding. 100
maxMemoryUsageInMB The (approximate) maximum memory that jpeg should allocate while attempting to decode the image in mebibyte. Images requiring more memory than this will throw an error instead of decoding. 512

Download Details:

Author: DevSnowflake

Source Code: https://github.com/DevSnowflake/jpeg

#deno #nodejs #node #javascript

What is GEEK

Buddha Community

JPEG Encoder/Decoder for Deno
Idris Brhane

Idris Brhane

1612613400

JPEG Encoder/Decoder for Deno

JPEG

JPEG Encoder/Decoder for Deno based on Node’s jpeg-js.

Example

Decode JPEG

import JPEG from "https://deno.land/x/jpeg/mod.ts";

const img = await Deno.readFile("./img.jpg");
const raw = JPEG.decode(img);

console.log(raw);

/*
{
  width: 850,
  height: 571,
  exifBuffer: undefined,
  data: Buffer(1941400) [
     78,  73,  83, 255,  86,  81,  91, 255,  82,  77,  85, 255,  68,  63,  71,
    255,  61,  56,  64, 255,  67,  62,  70, 255,  73,  68,  76, 255,  71,  66,
     74, 255,  65,  60,  66, 255,  75,  70,  76, 255,  83,  78,  84, 255,  81,
     76,  82, 255,  75,  71,  74, 255,  79,  75,  78, 255,  96,  92,  95, 255,
    113, 109, 112, 255,  95,  92,  99, 255,  86,  83,  90, 255,  89,  86,  93,
    255,  91,  88,  95, 255,  74,  71,  78, 255,  57,  54,  61, 255,  65,  62,
     69, 255,  83,  80,  87, 255,  83,  80,  87, 255,
    ... 1941300 more items
  ]
}
*/

Encoding JPEG

import JPEG from "https://deno.land/x/jpeg/mod.ts";

const width = 320, height = 180;
const frameData = new Uint8Array(width * height * 4);

let i = 0;
while(i < frameData.length) {
    frameData[i++] = 255; // red
    frameData[i++] = 66; // green
    frameData[i++] = 159; // blue
    frameData[i++] = 0; // alpha - ignored in JPEGs
}

const rawImageData = {
    data: frameData,
    width: width,
    height: height,
};
var jpegImageData = JPEG.encode(rawImageData, 50);
console.log(jpegImageData);

Deno.writeFileSync("./test/enc.jpg", jpegImageData.data);

/*
{
  data: Uint8Array(2222) [
    255, 216, 255, 224,  0,  16,  74,  70,  73,  70,   0,   1,   1,  0,  0,
      1,   0,   1,   0,  0, 255, 219,   0, 132,   0,  16,  11,  12, 14, 12,
     10,  16,  14,  13, 14,  18,  17,  16,  19,  24,  40,  26,  24, 22, 22,
     24,  49,  35,  37, 29,  40,  58,  51,  61,  60,  57,  51,  56, 55, 64,
     72,  92,  78,  64, 68,  87,  69,  55,  56,  80, 109,  81,  87, 95, 98,
    103, 104, 103,  62, 77, 113, 121, 112, 100, 120,  92, 101, 103, 99,  1,
     17,  18,  18,  24, 21,  24,  47,  26,  26,  47,
    ... 2122 more items
  ],
  width: 320,
  height: 180
}
*/

Options

Decode Options

Option Description Default
colorTransform Transform alternate colorspaces like YCbCr. undefined means respect the default behavior encoded in metadata. undefined
useTArray Decode pixels into a typed Uint8Array instead of a Buffer. false
formatAsRGBA Decode pixels into RGBA vs. RGB. true
tolerantDecoding Be more tolerant when encountering technically invalid JPEGs. true
maxResolutionInMP The maximum resolution image that jpeg should attempt to decode in megapixels. Images larger than this resolution will throw an error instead of decoding. 100
maxMemoryUsageInMB The (approximate) maximum memory that jpeg should allocate while attempting to decode the image in mebibyte. Images requiring more memory than this will throw an error instead of decoding. 512

Download Details:

Author: DevSnowflake

Source Code: https://github.com/DevSnowflake/jpeg

#deno #nodejs #node #javascript

Andrew French

1600755840

A pure TypeScript JPEG encoder and decoder for deno

jpeg.ts

A pure TypeScript JPEG encoder and decoder for deno

decoder

import { decode } from "https://deno.land/x/jpeg.ts/mod.ts"

//read image data:
let raw = await Deno.readFile(fullPath)
//decode"
let result = decode(raw);

//result.width: Image width
//result.height: Image height

//result.data[0] -> Red
//result.data[1] -> Green
//result.data[2] -> Blue
//result.data[3] -> Alpha
//...

// result.data is an array of RGBa colors

Also you can access the pixel of the image:

import { decode } from "https://deno.land/x/jpeg.ts/mod.ts"

//read image data:
let raw = await Deno.readFile(fullPath)
//decode"
let result = decode(raw);

let pix = result.getPixel(12, 33); // -> { r: 0, g: 0, b: 254, a: 255 }
// result.getPixel(x, y)
//while  0 <= x < result.width   and    0 <= y < result.height

encoder

import { encode, Image } from "https://deno.land/x/jpeg.ts/mod.ts"

// make image with red gree blue and alpha colors

let image: Image = {
    width: 2,
    height: 2,
    data: new Uint8Array( [
        255,0,0,1,
        0,255,0,1,
        0,0,255,1,
        255,255,0,1,
    ])
}

let raw = encode(image, 100); //Quality 100 (default is 50)
//save the image
await Deno.writeFile('rgb.jpg', raw.data);

Download Details:

Author: fakoua

Source Code: https://github.com/fakoua/jpeg.ts

#deno #nodejs #node #javascript

Bongani  Ngema

Bongani Ngema

1645409220

He: HTML Entity Encoder/decoder

he   

he (for “HTML entities”) is a robust HTML entity encoder/decoder written in JavaScript. It supports all standardized named character references as per HTML, handles ambiguous ampersands and other edge cases just like a browser would, has an extensive test suite, and — contrary to many other JavaScript solutions — he handles astral Unicode symbols just fine. An online demo is available.

Installation

Via npm:

npm install he

Via Bower:

bower install he

Via Component:

component install mathiasbynens/he

In a browser:

<script src="he.js"></script>

In Node.js, io.js, Narwhal, and RingoJS:

var he = require('he');

In Rhino:

load('he.js');

Using an AMD loader like RequireJS:

require(
  {
    'paths': {
      'he': 'path/to/he'
    }
  },
  ['he'],
  function(he) {
    console.log(he);
  }
);

API

he.version

A string representing the semantic version number.

he.encode(text, options)

This function takes a string of text and encodes (by default) any symbols that aren’t printable ASCII symbols and &, <, >, ", ', and `, replacing them with character references.

he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

As long as the input string contains allowed code points only, the return value of this function is always valid HTML. Any (invalid) code points that cannot be represented using a character reference in the input are not encoded:

he.encode('foo \0 bar');
// → 'foo \0 bar'

However, enabling the strict option causes invalid code points to throw an exception. With strict enabled, he.encode either throws (if the input contains invalid code points) or returns a string of valid HTML.

The options object is optional. It recognizes the following properties:

useNamedReferences

The default value for the useNamedReferences option is false. This means that encode() will not use any named character references (e.g. &copy;) in the output — hexadecimal escapes (e.g. &#xA9;) will be used instead. Set it to true to enable the use of named references.

Note that if compatibility with older browsers is a concern, this option should remain disabled.

// Using the global default setting (defaults to `false`):
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly disallow named references:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'useNamedReferences': false
});
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly allow named references:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'useNamedReferences': true
});
// → 'foo &copy; bar &ne; baz &#x1D306; qux'

decimal

The default value for the decimal option is false. If the option is enabled, encode will generally use decimal escapes (e.g. &#169;) rather than hexadecimal escapes (e.g. &#xA9;). Beside of this replacement, the basic behavior remains the same when combined with other options. For example: if both options useNamedReferences and decimal are enabled, named references (e.g. &copy;) are used over decimal escapes. HTML entities without a named reference are encoded using decimal escapes.

// Using the global default setting (defaults to `false`):
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly disable decimal escapes:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'decimal': false
});
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly enable decimal escapes:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'decimal': true
});
// → 'foo &#169; bar &#8800; baz &#119558; qux'

// Passing an `options` object to `encode`, to explicitly allow named references and decimal escapes:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'useNamedReferences': true,
  'decimal': true
});
// → 'foo &copy; bar &ne; baz &#119558; qux'

encodeEverything

The default value for the encodeEverything option is false. This means that encode() will not use any character references for printable ASCII symbols that don’t need escaping. Set it to true to encode every symbol in the input string. When set to true, this option takes precedence over allowUnsafeSymbols (i.e. setting the latter to true in such a case has no effect).

// Using the global default setting (defaults to `false`):
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &#xA9; bar &#x2260; baz &#x1D306; qux'

// Passing an `options` object to `encode`, to explicitly encode all symbols:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'encodeEverything': true
});
// → '&#x66;&#x6F;&#x6F;&#x20;&#xA9;&#x20;&#x62;&#x61;&#x72;&#x20;&#x2260;&#x20;&#x62;&#x61;&#x7A;&#x20;&#x1D306;&#x20;&#x71;&#x75;&#x78;'

// This setting can be combined with the `useNamedReferences` option:
he.encode('foo © bar ≠ baz 𝌆 qux', {
  'encodeEverything': true,
  'useNamedReferences': true
});
// → '&#x66;&#x6F;&#x6F;&#x20;&copy;&#x20;&#x62;&#x61;&#x72;&#x20;&ne;&#x20;&#x62;&#x61;&#x7A;&#x20;&#x1D306;&#x20;&#x71;&#x75;&#x78;'

strict

The default value for the strict option is false. This means that encode() will encode any HTML text content you feed it, even if it contains any symbols that cause parse errors. To throw an error when such invalid HTML is encountered, set the strict option to true. This option makes it possible to use he as part of HTML parsers and HTML validators.

// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
he.encode('\x01');
// → '&#x1;'

// Passing an `options` object to `encode`, to explicitly enable error-tolerant mode:
he.encode('\x01', {
  'strict': false
});
// → '&#x1;'

// Passing an `options` object to `encode`, to explicitly enable strict mode:
he.encode('\x01', {
  'strict': true
});
// → Parse error

allowUnsafeSymbols

The default value for the allowUnsafeSymbols option is false. This means that characters that are unsafe for use in HTML content (&, <, >, ", ', and `) will be encoded. When set to true, only non-ASCII characters will be encoded. If the encodeEverything option is set to true, this option will be ignored.

he.encode('foo © and & ampersand', {
  'allowUnsafeSymbols': true
});
// → 'foo &#xA9; and & ampersand'

Overriding default encode options globally

The global default setting can be overridden by modifying the he.encode.options object. This saves you from passing in an options object for every call to encode if you want to use the non-default setting.

// Read the global default setting:
he.encode.options.useNamedReferences;
// → `false` by default

// Override the global default setting:
he.encode.options.useNamedReferences = true;

// Using the global default setting, which is now `true`:
he.encode('foo © bar ≠ baz 𝌆 qux');
// → 'foo &copy; bar &ne; baz &#x1D306; qux'

he.decode(html, options)

This function takes a string of HTML and decodes any named and numerical character references in it using the algorithm described in section 12.2.4.69 of the HTML spec.

he.decode('foo &copy; bar &ne; baz &#x1D306; qux');
// → 'foo © bar ≠ baz 𝌆 qux'

The options object is optional. It recognizes the following properties:

isAttributeValue

The default value for the isAttributeValue option is false. This means that decode() will decode the string as if it were used in a text context in an HTML document. HTML has different rules for parsing character references in attribute values — set this option to true to treat the input string as if it were used as an attribute value.

// Using the global default setting (defaults to `false`, i.e. HTML text context):
he.decode('foo&ampbar');
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly assume an HTML text context:
he.decode('foo&ampbar', {
  'isAttributeValue': false
});
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly assume an HTML attribute value context:
he.decode('foo&ampbar', {
  'isAttributeValue': true
});
// → 'foo&ampbar'

strict

The default value for the strict option is false. This means that decode() will decode any HTML text content you feed it, even if it contains any entities that cause parse errors. To throw an error when such invalid HTML is encountered, set the strict option to true. This option makes it possible to use he as part of HTML parsers and HTML validators.

// Using the global default setting (defaults to `false`, i.e. error-tolerant mode):
he.decode('foo&ampbar');
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly enable error-tolerant mode:
he.decode('foo&ampbar', {
  'strict': false
});
// → 'foo&bar'

// Passing an `options` object to `decode`, to explicitly enable strict mode:
he.decode('foo&ampbar', {
  'strict': true
});
// → Parse error

Overriding default decode options globally

The global default settings for the decode function can be overridden by modifying the he.decode.options object. This saves you from passing in an options object for every call to decode if you want to use a non-default setting.

// Read the global default setting:
he.decode.options.isAttributeValue;
// → `false` by default

// Override the global default setting:
he.decode.options.isAttributeValue = true;

// Using the global default setting, which is now `true`:
he.decode('foo&ampbar');
// → 'foo&ampbar'

he.escape(text)

This function takes a string of text and escapes it for use in text contexts in XML or HTML documents. Only the following characters are escaped: &, <, >, ", ', and `.

he.escape('<img src=\'x\' onerror="prompt(1)">');
// → '&lt;img src=&#x27;x&#x27; onerror=&quot;prompt(1)&quot;&gt;'

he.unescape(html, options)

he.unescape is an alias for he.decode. It takes a string of HTML and decodes any named and numerical character references in it.

Using the he binary

To use the he binary in your shell, simply install he globally using npm:

npm install -g he

After that you will be able to encode/decode HTML entities from the command line:

$ he --encode 'föo ♥ bår 𝌆 baz'
f&#xF6;o &#x2665; b&#xE5;r &#x1D306; baz

$ he --encode --use-named-refs 'föo ♥ bår 𝌆 baz'
f&ouml;o &hearts; b&aring;r &#x1D306; baz

$ he --decode 'f&ouml;o &hearts; b&aring;r &#x1D306; baz'
föo ♥ bår 𝌆 baz

Read a local text file, encode it for use in an HTML text context, and save the result to a new file:

$ he --encode < foo.txt > foo-escaped.html

Or do the same with an online text file:

$ curl -sL "http://git.io/HnfEaw" | he --encode > escaped.html

Or, the opposite — read a local file containing a snippet of HTML in a text context, decode it back to plain text, and save the result to a new file:

$ he --decode < foo-escaped.html > foo.txt

Or do the same with an online HTML snippet:

$ curl -sL "http://git.io/HnfEaw" | he --decode > decoded.txt

See he --help for the full list of options.

Support

he has been tested in at least:

  • Chrome 27-50
  • Firefox 3-45
  • Safari 4-9
  • Opera 10-12, 15–37
  • IE 6–11
  • Edge
  • Narwhal 0.3.2
  • Node.js v0.10, v0.12, v4, v5
  • PhantomJS 1.9.0
  • Rhino 1.7RC4
  • RingoJS 0.8-0.11

Unit tests & code coverage

After cloning this repository, run npm install to install the dependencies needed for he development and testing. You may want to install Istanbul globally using npm install istanbul -g.

Once that’s done, you can run the unit tests in Node using npm test or node tests/tests.js. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use grunt test.

To generate the code coverage report, use grunt cover.

Acknowledgements

Thanks to Simon Pieters (@zcorpan) for the many suggestions.

Author: Mathiasbynens
Source Code: https://github.com/mathiasbynens/he
License: MIT License

#node #javascript #encode #decode 

A Set of Codecs for Encode and Decode Data

A set of codecs for encode and decode data.

Features

Base16

Supported hex alphabet and custom alphabets.

Hex

  • Codec - Base16Codec
  • codec variable - base16 (and alias hex)
  • Functions - base16Encode (hexEncode), base16Decode (hexDecode)

Custom

  • Codec - Base16CodecCustom
  • Description - You can pass custom alphabet to Codec for encode and decode data by this alphabet.

Base32

Supported Rfc, RfcHex, Crockford, ZBase, GeoHash, WordSafe, Custom alphabets

Rfc

  • Codec - Base32CodecRfc
  • codec variable - base32Rfc
  • Functions - base32RfcEncode, base32RfcDecode

RfcHex

  • Codec - Base32CodecRfcHex
  • codec variable - base32RfcHex
  • Functions - base32RfcHexEncode, base32RfcHexDecode

Crockford

  • Codec - Base32CodecCrockford
  • codec variable - base32Crockford
  • Functions - base32CrockfordEncode, base32CrockfordDecode

ZBase

  • Codec - Base32CodecZBase
  • codec variable - base32ZBase
  • Functions - base32ZBaseEncode, base32ZBaseDecode

GeoHash

  • Codec - Base32CodecGeoHash
  • codec variable - base32GeoHash
  • Functions - base32GeoHashEncode, base32GeoHashDecode

WordSafe

  • Codec - Base32CodecWordSafe
  • codec variable - base32WordSafe
  • Functions - base32WordSafeEncode, base32WordSafeDecode

Custom

  • Codec - Base32CodecCustom
  • Description - You can pass custom alphabet and padding to Codec for encode and decode data by this alphabet.

Base58

Supported Bitcoin, Flickr, Ripple, Custom alphabets

Bitcoin

  • Codec - Base58CodecBitcoin
  • codec variable - base58Bitcoin
  • Functions - base58BitcoinEncode, base58BitcoinDecode

Flickr

  • Codec - Base58CodecFlickr
  • codec variable - base58Flickr
  • Functions - base58FlickrEncode, base58FlickrDecode

Ripple

  • Codec - Base58CodecRipple
  • codec variable - base58Ripple
  • Functions - base58RippleEncode, base58RippleDecode

Custom

  • Codec - Base58CodecCustom
  • Description - You can pass custom alphabet and decodeList to Codec for encode and decode data by this alphabet.

Base58Check

  • Functions - base58CheckEncode, base58CheckDecode

Base85

Supported Ascii85, ZeroMq, IPv6

Ascii85

  • Codec - Base85CodecAscii
  • codec variable - base85Ascii
  • Functions - base85AsciiEncode, base85AsciiDecode

ZeroMq

  • Codec - Base85CodecZ
  • codec variable - base85Z
  • Functions - base85ZEncode, base85ZDecode

IPv6

  • Codec - Base85CodecIPv6
  • codec variable - base85IPv6
  • Functions - base85IPv6Encode, base85IPv6Decode

Use this package as a library

Depend on it

Run this command:

With Dart:

 $ dart pub add base_codecs

With Flutter:

 $ flutter pub add base_codecs

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  base_codecs: ^1.0.0

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:base_codecs/base_codecs.dart'; 

example/base_codecs_example.dart

import 'dart:convert';
import 'dart:typed_data';

import 'package:base_codecs/base_codecs.dart';

void main() {
  const testString =
      "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";

  /// Base16 (Hex)
  const data = [0xDE, 0xAD, 0xBE, 0xEF];
  hexEncode(Uint8List.fromList(data)); //DEADBEEF
  hexDecode('DEADBEEF'); // == data

  /// Base16 Custom
  const custom = Base16CodecCustom('ABCDEF9876543210');
  final customData = Uint8List.fromList(
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
  );
  custom.encode(customData); // AAABACADAEAFA9A8A7A6A5A4A3A2A1A0
  custom.decode('AAABACADAEAFA9A8A7A6A5A4A3A2A1A0'); // == customData

  /// Base32
  /// RFC
  const encoded =
      "JVQW4IDJOMQGI2LTORUW4Z3VNFZWQZLEFQQG433UEBXW43DZEBRHSIDINFZSA4TFMFZW63RMEBRHK5BAMJ4SA5DINFZSA43JNZTXK3DBOIQHAYLTONUW63RAMZZG63JAN52GQZLSEBQW42LNMFWHGLBAO5UGSY3IEBUXGIDBEBWHK43UEBXWMIDUNBSSA3LJNZSCYIDUNBQXIIDCPEQGCIDQMVZHGZLWMVZGC3TDMUQG6ZRAMRSWY2LHNB2CA2LOEB2GQZJAMNXW45DJNZ2WKZBAMFXGIIDJNZSGKZTBORUWOYLCNRSSAZ3FNZSXEYLUNFXW4IDPMYQGW3TPO5WGKZDHMUWCAZLYMNSWKZDTEB2GQZJAONUG64TUEB3GK2DFNVSW4Y3FEBXWMIDBNZ4SAY3BOJXGC3BAOBWGKYLTOVZGKLQ=";

  base32RfcEncode(Uint8List.fromList(utf8.encode(testString)));

  base32RfcDecode(encoded);

  /// RFC HEX

  const encodedRFCHex =
      "9LGMS839ECG68QBJEHKMSPRLD5PMGPB45GG6SRRK41NMSR3P41H7I838D5PI0SJ5C5PMURHC41H7AT10C9SI0T38D5PI0SR9DPJNAR31E8G70OBJEDKMURH0CPP6UR90DTQ6GPBI41GMSQBDC5M76B10ETK6IOR841KN683141M7ASRK41NMC83KD1II0RB9DPI2O83KD1GN8832F4G6283GCLP76PBMCLP62RJ3CKG6UPH0CHIMOQB7D1Q20QBE41Q6GP90CDNMST39DPQMAP10C5N68839DPI6APJ1EHKMEOB2DHII0PR5DPIN4OBKD5NMS83FCOG6MRJFETM6AP37CKM20PBOCDIMAP3J41Q6GP90EDK6USJK41R6AQ35DLIMSOR541NMC831DPSI0OR1E9N62R10E1M6AOBJELP6ABG=";

  base32RfcHexEncode(Uint8List.fromList(utf8.encode(testString)));

  base32RfcHexDecode(encodedRFCHex);

  /// ZBase
  const encodedZbase =
      "JIOSHEDJQCOGE4MUQTWSH35IPF3SO3MRFOOGH55WRBZSH5D3RBT81EDEPF31YHUFCF3S65TCRBT8K7BYCJH1Y7DEPF31YH5JP3UZK5DBQEO8YAMUQPWS65TYC33G65JYP74GO3M1RBOSH4MPCFS8GMBYQ7WG1A5ERBWZGEDBRBS8KH5WRBZSCEDWPB11Y5MJP31NAEDWPBOZEEDNXROGNEDOCI38G3MSCI3GN5UDCWOG63TYCT1SA4M8PB4NY4MQRB4GO3JYCPZSH7DJP34SK3BYCFZGEEDJP31GK3UBQTWSQAMNPT11Y35FP31ZRAMWPFZSHEDXCAOGS5UXQ7SGK3D8CWSNY3MACP1SK3DURB4GO3JYQPWG6HUWRB5GK4DFPI1SHA5FRBZSCEDBP3H1YA5BQJZGN5BYQBSGKAMUQI3GKMO";

  base32ZBaseEncode(Uint8List.fromList(utf8.encode(testString)));

  base32ZBaseDecode(encodedZbase);

  const encodedCrockford =
      "9NGPW839ECG68TBKEHMPWSVND5SPGSB45GG6WVVM41QPWV3S41H7J838D5SJ0WK5C5SPYVHC41H7AX10C9WJ0X38D5SJ0WV9DSKQAV31E8G70RBKEDMPYVH0CSS6YV90DXT6GSBJ41GPWTBDC5P76B10EXM6JRV841MQ683141P7AWVM41QPC83MD1JJ0VB9DSJ2R83MD1GQ8832F4G6283GCNS76SBPCNS62VK3CMG6YSH0CHJPRTB7D1T20TBE41T6GS90CDQPWX39DSTPAS10C5Q68839DSJ6ASK1EHMPERB2DHJJ0SV5DSJQ4RBMD5QPW83FCRG6PVKFEXP6AS37CMP20SBRCDJPAS3K41T6GS90EDM6YWKM41V6AT35DNJPWRV541QPC831DSWJ0RV1E9Q62V10E1P6ARBKENS6ABG";

  base32CrockfordEncode(Uint8List.fromList(utf8.encode(testString)));

  base32CrockfordDecode(encodedCrockford);

  /// WordSafe
  const encodedWordSafe =
      "FfRgrC5FPJR8CpHXPVcgrmqfM7mgRmH67RR8rqqc63hgrq5m63V9WC5CM7mW2rX7J7mgwqVJ63V9Gv32JFrW2v5CM7mW2rqFMmXhGq53PCR92jHXPMcgwqV2Jmm8wqF2Mvp8RmHW63RgrpHMJ7g98H32Pvc8WjqC63ch8C5363g9Grqc63hgJC5cM3WW2qHFMmW4jC5cM3RhCC54Q6R84C5RJfm98mHgJfm84qX5JcR8wmV2JVWgjpH9M3p42pHP63p8RmF2JMhgrv5FMmpgGm32J7h8CC5FMmW8GmX3PVcgPjH4MVWW2mq7MmWh6jHcM7hgrC5QJjR8gqXQPvg8Gm59Jcg42mHjJMWgGm5X63p8RmF2PMc8wrXc63q8Gp57MfWgrjq763hgJC53MmrW2jq3PFh84q32P3g8GjHXPfm8GHR";

  base32WordSafeEncode(Uint8List.fromList(utf8.encode(testString)));

  base32WordSafeDecode(encodedWordSafe);

  /// GeoHash
  const encodedGeoHash =
      "9phqw839fdh68ucmfjnqwtvpe5tqhtc45hh6wvvn41rqwv3t41j7k838e5tk0wm5d5tqyvjd41j7bx10d9wk0x38e5tk0wv9etmrbv31f8h70scmfenqyvj0dtt6yv90exu6htck41hqwuced5q76c10fxn6ksv841nr683141q7bwvn41rqd83ne1kk0vc9etk2s83ne1hr8832g4h6283hdpt76tcqdpt62vm3dnh6ytj0djkqsuc7e1u20ucf41u6ht90derqwx39etuqbt10d5r68839etk6btm1fjnqfsc2ejkk0tv5etkr4scne5rqw83gdsh6qvmgfxq6bt37dnq20tcsdekqbt3m41u6ht90fen6ywmn41v6bu35epkqwsv541rqd831etwk0sv1f9r62v10f1q6bscmfpt6bch";

  base32GeoHashEncode(Uint8List.fromList(utf8.encode(testString)));

  base32GeoHashDecode(encodedGeoHash);

  ///Custom'
  const codec = Base32CodecCustom("0123456789ABCDEFGHJKMNPQRSTVWXYZ", '');
  const encodedCustom =
      "9NGPW839ECG68TBKEHMPWSVND5SPGSB45GG6WVVM41QPWV3S41H7J838D5SJ0WK5C5SPYVHC41H7AX10C9WJ0X38D5SJ0WV9DSKQAV31E8G70RBKEDMPYVH0CSS6YV90DXT6GSBJ41GPWTBDC5P76B10EXM6JRV841MQ683141P7AWVM41QPC83MD1JJ0VB9DSJ2R83MD1GQ8832F4G6283GCNS76SBPCNS62VK3CMG6YSH0CHJPRTB7D1T20TBE41T6GS90CDQPWX39DSTPAS10C5Q68839DSJ6ASK1EHMPERB2DHJJ0SV5DSJQ4RBMD5QPW83FCRG6PVKFEXP6AS37CMP20SBRCDJPAS3K41T6GS90EDM6YWKM41V6AT35DNJPWRV541QPC831DSWJ0RV1E9Q62V10E1P6ARBKENS6ABG";

  codec.encode(Uint8List.fromList(utf8.encode(testString)));

  codec.decode(encodedCustom);

  /// Base58

  const encodedBitcoin =
      "2KG5obUH7D2G2qLPjujWXdCd1FK6heTdfCjVn1MwP3unVrwcoTz3QyxtBe8Dpxfc5Afnf6VL2b4Ae9RWHEJ957WJpTXTXKcSyFZb17ALWU1BcBsNv2Cncqm5qTadzLcryeftfjtFZfJ14EKKf7UVd5h7UXFSqpmB144w2Eyb9gwvh7mofZpc7oSQv4ZSso9tD1589EjLERTebQoFtt8isgKarX4HGRWUpQCRkAPWuiNrYeV4XEmE4ez4f2mWN1vgGPcX8mKm7RXjYnQ1aGF3oZvKrQQ1ySEq4b5fLvQxcGzCp9xsVdfgK3pXC1RQPf8nyhik8JEnGdXV999wjaj7ggrcEtmkZH41ynpvSYkDecL8nNMT";

  base58BitcoinEncode(Uint8List.fromList(utf8.encode(testString)));

  base58BitcoinDecode(encodedBitcoin);

  /// Flickr

  const encodedFlickr =
      '2jg5NAth7d2g2QkoJUJvwCcC1fj6GDsCEcJuM1mWo3UMuRWBNsZ3pYXTbD8dPXEB5aEME6uk2A4aD9qvhei957viPswswjBrYfyA17akvt1bBbSnV2cMBQL5QszCZkBRYDETEJTfyEi14ejjE7tuC5G7twfrQPLb144W2eYA9FWVG7LNEyPB7NrpV4yrSN9Td1589eJkeqsDApNfTT8HSFjzRw4hgqvtPpcqKaovUHnRxDu4weLe4DZ4E2Lvn1VFgoBw8LjL7qwJxMp1zgf3NyVjRpp1YreQ4A5EkVpXBgZcP9XSuCEFj3Pwc1qpoE8MYGHK8ieMgCwu999WJzJ7FFRBeTLKyh41YMPVrxKdDBk8Mnms';

  base58FlickrEncode(Uint8List.fromList(utf8.encode(testString)));

  base58FlickrDecode(encodedFlickr);

  /// Ripple

  const encodedRipple =
      'pKGnob7HfDpGpqLPjujWXdUdrEKa6eTdCUjV8rMAPsu8ViAcoTzsQyxtBe3DFxCcnwC8CaVLpbhwe9RWHNJ9nfWJFTXTXKcSyEZbrfwLW7rBcB14vpU8cqmnqT2dzLciyeCtCjtEZCJrhNKKCf7Vdn6f7XESqFmBrhhApNyb9gAv6fmoCZFcfoSQvhZS1o9tDrn39NjLNRTebQoEtt351gK2iXhHGRW7FQURkwPWu54iYeVhXNmNhezhCpmW4rvgGPcX3mKmfRXjY8Qr2GEsoZvKiQQrySNqhbnCLvQxcGzUF9x1VdCgKsFXUrRQPC38y65k3JN8GdXV999Aj2jfggicNtmkZHhry8FvSYkDecL384MT';

  base58RippleEncode(Uint8List.fromList(utf8.encode(testString)));

  base58RippleDecode(encodedRipple);

  /// Base58Check

  const encodedCheck = "5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr";
  const decodedCheck =
      "80EDDBDC1168F1DAEADBD3E44C1E3F8F5A284C2029F78AD26AF98583A499DE5B19";

  base58CheckEncode(base16.decode(decodedCheck));

  base16.encode(base58CheckDecode(encodedCheck));

  ///Base85

  /// Ascii
  final zeroDecoded = Uint8List.fromList(
    [0, 0, 0, 0, 0, 0, 0, 0, 0xd9, 0x47, 0xa3, 0xd5, 0, 0, 0, 0],
  );

  base85AsciiEncode(Uint8List.fromList(utf8.encode(testString)));

  base85AsciiEncode(zeroDecoded);

  /// Z85
  const rfcTestData = [0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B];
  const rfcTestDataEncoded = "HelloWorld";

  base85ZEncode(
    Uint8List.fromList(rfcTestData),
  );

  base85ZDecode(rfcTestDataEncoded);

  /// IPv6
  //  1080:0:0:0:8:800:200C:417A from RFC 1924
  const address = '108000000000000000080800200C417A';
  const encodedIPv6 = "4)+k&C#VzJ4br>0wv%Yp";

  base85IPv6Encode(
    Uint8List.fromList(base16.decode(address)),
  );

  base85IPv6Decode(encodedIPv6);
} 

Download Details:

Author: KirsApps

Source Code: https://github.com/KirsApps/base_codecs

#dart  #decode  #encode 

URL Encoding in HTML - HTML URL Encode Characters

HTML URL Encoding

Uniform Resource Locator or URL is used as the address of a document on the web. It can be composed of words, typically the Domain Name Server(DNS), or IP address. For example, https://data-flair.training/blogs/ is a URL.

The structure of this URL is as follows-

scheme://prefix.domain:port/path/filename

Here:

Scheme – Defines the internet service type, commonly http or https.

Prefix – Defines the domain prefix, www.

Domain – It defines the domain name of the internet, data-flair.training

Port – Defines the host’s port number, 80 is the default port number for http.

Path – Defines the path at the server.

Filename – It defines the name of the file or the document that is being displayed.

HTML URL Schemes

Some common URL schemes are-

  • Http(HyperText Transfer Protocol) – Used for common web-pages. It is not encrypted.
  • Https(Secure HyperText Transfer Protocol) – Used for secure web-pages. It is encrypted.
  • ftp(File Transfer Protocol) – Used for downloading and uploading files.

HTML URL Encode Characters

URL encoding is the practice of translating characters within URL to ASCII so that they can be easily transmitted and get accepted by all the browsers present globally on the internet. The non-ASCII characters are shown with a percentage sign (%) followed by hexadecimal digits.

Hence, URL encoding basically involves replacing a character that does not start with ‘%’ followed by hexadecimal digits to the ASCII character set. For example, if you want to type a space in the URL, you write it as %20. $ is replaced by %24.

#html tutorials #html encoded characters #html url encode #url encoded