3.3.1 • Published 8 months ago

@itk-wasm/compress-stringify v3.3.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

@itk-wasm/compress-stringify

npm version

Zstandard compression and decompression and base64 encoding and decoding in WebAssembly.

👨‍💻 Live API Demo

🕮 Documentation 📚

Installation

npm install @itk-wasm/compress-stringify

Usage

Browser interface

Import:

import {
  imageToJson,
  jsonToImage,
  meshToJson,
  jsonToMesh,
  polyDataToJson,
  jsonToPolyData,
  compressStringify,
  parseStringDecompress,
  setPipelinesBaseUrl,
  getPipelinesBaseUrl,
} from "@itk-wasm/compress-stringify"

Functions

imageToJson

Compress and encode an itk-wasm Image into a JSON compatible object.

async function imageToJson(
  image: Image,
  options: ImageToJsonOptions = {}
): Promise<ImageToJsonResult>
ParameterTypeDescription
imageImageInput image

ImageToJsonOptions interface:

PropertyTypeDescription
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

ImageToJsonResult interface:

PropertyTypeDescription
encodedImageJsonOutput encoded image JSON, binary data is a compressed string
webWorkerWorkerWebWorker used for computation.

jsonToImage

Decode and decompress an itk-wasm Image JSON, binary data compressed and converted to a string.

async function jsonToImage(
  encoded: ImageJson,
  options: JsonToImageOptions = {}
): Promise<JsonToImageResult>
ParameterTypeDescription
encodedImageJsonInput encoded image

JsonToImageOptions interface:

PropertyTypeDescription
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

JsonToImageResult interface:

PropertyTypeDescription
decodedImageOutput decoded image
webWorkerWorkerWebWorker used for computation.

meshToJson

Compress and encode an itk-wasm Mesh into a JSON compatible object.

async function meshToJson(
  mesh: Mesh,
  options: MeshToJsonOptions = {}
): Promise<MeshToJsonResult>
ParameterTypeDescription
meshMeshInput mesh

MeshToJsonOptions interface:

PropertyTypeDescription
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

MeshToJsonResult interface:

PropertyTypeDescription
encodedMeshJsonOutput encoded mesh JSON, binary data is a compressed string
webWorkerWorkerWebWorker used for computation.

jsonToMesh

Decode and decompress an itk-wasm Mesh JSON, binary data compressed and converted to a string.

async function jsonToMesh(
  encoded: MeshJson,
  options: JsonToMeshOptions = {}
): Promise<JsonToMeshResult>
ParameterTypeDescription
encodedMeshJsonInput encoded mesh

JsonToMeshOptions interface:

PropertyTypeDescription
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

JsonToMeshResult interface:

PropertyTypeDescription
decodedMeshOutput decoded mesh
webWorkerWorkerWebWorker used for computation.

polyDataToJson

Compress and encode an itk-wasm PolyData into a JSON compatible object.

async function polyDataToJson(
  polyData: PolyData,
  options: PolyDataToJsonOptions = {}
): Promise<PolyDataToJsonResult>
ParameterTypeDescription
polyDataPolyDataInput polyData

PolyDataToJsonOptions interface:

PropertyTypeDescription
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

PolyDataToJsonResult interface:

PropertyTypeDescription
encodedPolyDataJsonOutput encoded polyData JSON, binary data is a compressed string
webWorkerWorkerWebWorker used for computation.

jsonToPolyData

Decode and decompress an itk-wasm PolyData JSON compatible object.

async function jsonToPolyData(
  encoded: PolyDataJson,
  options: JsonToPolyDataOptions = {}
): Promise<JsonToPolyDataResult>
ParameterTypeDescription
encodedPolyDataJsonInput encoded polyData

JsonToPolyDataOptions interface:

PropertyTypeDescription
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

JsonToPolyDataResult interface:

PropertyTypeDescription
decodedPolyDataOutput decoded polyData
webWorkerWorkerWebWorker used for computation.

compressStringify

Given a binary, compress and optionally base64 encode.

async function compressStringify(
  input: Uint8Array,
  options: CompressStringifyOptions = {}
) : Promise<CompressStringifyResult>
ParameterTypeDescription
inputUint8ArrayInput binary

CompressStringifyOptions interface:

PropertyTypeDescription
stringifybooleanStringify the output
compressionLevelnumberCompression level, typically 1-9
dataUrlPrefixstringdataURL prefix
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

CompressStringifyResult interface:

PropertyTypeDescription
outputUint8ArrayOutput compressed binary
webWorkerWorkerWebWorker used for computation.

parseStringDecompress

Given a binary or string produced with compress-stringify, decompress and optionally base64 decode.

async function parseStringDecompress(
  input: Uint8Array,
  options: ParseStringDecompressOptions = {}
) : Promise<ParseStringDecompressResult>
ParameterTypeDescription
inputUint8ArrayCompressed input

ParseStringDecompressOptions interface:

PropertyTypeDescription
parseStringbooleanParse the input string before decompression
webWorkernull or Worker or booleanWebWorker for computation. Set to null to create a new worker. Or, pass an existing worker. Or, set to false to run in the current thread / worker.
noCopybooleanWhen SharedArrayBuffer's are not available, do not copy inputs.

ParseStringDecompressResult interface:

PropertyTypeDescription
outputUint8ArrayOutput decompressed binary
webWorkerWorkerWebWorker used for computation.

setPipelinesBaseUrl

Set base URL for WebAssembly assets when vendored.

function setPipelinesBaseUrl(
  baseUrl: string | URL
) : void

getPipelinesBaseUrl

Get base URL for WebAssembly assets when vendored.

function getPipelinesBaseUrl() : string | URL

Node interface

Import:

import {
  imageToJsonNode,
  jsonToImageNode,
  meshToJsonNode,
  jsonToMeshNode,
  polyDataToJsonNode,
  jsonToPolyDataNode,
  compressStringifyNode,
  parseStringDecompressNode,
} from "@itk-wasm/compress-stringify"

imageToJsonNode

Compress and encode an itk-wasm Image into a JSON compatible object.

async function imageToJsonNode(image: Image): Promise<ImageToJsonNodeResult>
ParameterTypeDescription
imageImageInput image

ImageToJsonNodeResult interface:

PropertyTypeDescription
encodedImageJsonOutput encoded image JSON, binary data converted to a compressed string

jsonToImageNode

Decode and decompress an itk-wasm Image JSON compatible object.

async function jsonToImageNode(encoded: ImageJson): Promise<JsonToImageNodeResult>
ParameterTypeDescription
encodedstringInput encoded image

JsonToImageNodeResult interface:

PropertyTypeDescription
decodedImageOutput decoded image

meshToJsonNode

Compress and encode an itk-wasm Mesh into a JSON compatible object.

async function meshToJsonNode(mesh: Mesh): Promise<MeshToJsonNodeResult>
ParameterTypeDescription
meshMeshInput mesh

MeshToJsonNodeResult interface:

PropertyTypeDescription
encodedMeshJsonOutput encoded mesh JSON, binary data compressed and converted to a string

jsonToMeshNode

Decode and decompress an itk-wasm Mesh JSON compatible object.

async function jsonToMeshNode(encoded: MeshJson): Promise<JsonToMeshNodeResult>
ParameterTypeDescription
encodedMeshJsonInput encoded mesh

JsonToMeshNodeResult interface:

PropertyTypeDescription
decodedMeshOutput decoded mesh

polyDataToJsonNode

Compress and encode an itk-wasm PolyData into a JSON compatible object.

async function polyDataToJsonNode(polyData: PolyData): Promise<PolyDataToJsonNodeResult>
ParameterTypeDescription
polyDataPolyDataInput polyData

PolyDataToJsonNodeResult interface:

PropertyTypeDescription
encodedPolyDataJsonOutput encoded polyData JSON, binary data compressed and converted to a string

jsonToPolyDataNode

Decode and decompress an itk-wasm PolyData JSON string.

async function jsonToPolyDataNode(encoded: PolyDataJson): Promise<JsonToPolyDataNodeResult>
ParameterTypeDescription
encodedPolyDataJsonInput encoded polyData

JsonToPolyDataNodeResult interface:

PropertyTypeDescription
decodedPolyDataOutput decoded polyData

compressStringifyNode

Given a binary, compress and optionally base64 encode.

async function compressStringifyNode(
  input: Uint8Array,
  options: CompressStringifyNodeOptions = {}
) : Promise<CompressStringifyNodeResult>
ParameterTypeDescription
inputUint8ArrayInput binary

CompressStringifyNodeOptions interface:

PropertyTypeDescription
stringifybooleanStringify the output
compressionLevelnumberCompression level, typically 1-9
dataUrlPrefixstringdataURL prefix

CompressStringifyNodeResult interface:

PropertyTypeDescription
outputUint8ArrayOutput compressed binary

parseStringDecompressNode

Given a binary or string produced with compress-stringify, decompress and optionally base64 decode.

async function parseStringDecompressNode(
  input: Uint8Array,
  options: ParseStringDecompressNodeOptions = {}
) : Promise<ParseStringDecompressNodeResult>
ParameterTypeDescription
inputUint8ArrayCompressed input

ParseStringDecompressNodeOptions interface:

PropertyTypeDescription
parseStringbooleanParse the input string before decompression

ParseStringDecompressNodeResult interface:

PropertyTypeDescription
outputUint8ArrayOutput decompressed binary
3.3.1

8 months ago

3.3.0

10 months ago

3.2.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

0.5.3

2 years ago

2.0.1

2 years ago

0.6.1

2 years ago

0.5.2

2 years ago

2.0.0

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.5

2 years ago

0.5.0

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago