-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dojyorin/dev
various updates.
- Loading branch information
Showing
19 changed files
with
349 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Release | ||
"on": | ||
push: | ||
tags: v[0-9].[0-9].[0-9] | ||
jobs: | ||
release: | ||
name: 'Release: ${{github.ref_name}}' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: clone repository | ||
uses: actions/checkout@v3 | ||
- name: dispatch release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
generate_release_notes: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "Release", | ||
"on": { | ||
"push": { | ||
"tags": "v[0-9].[0-9].[0-9]" | ||
} | ||
}, | ||
"jobs": { | ||
"release": { | ||
"name": "Release: ${{github.ref_name}}", | ||
"runs-on": "ubuntu-latest", | ||
"steps": [{ | ||
"name": "clone repository", | ||
"uses": "actions/checkout@v3" | ||
}, { | ||
"name": "dispatch release", | ||
"uses": "softprops/action-gh-release@v1", | ||
"with": { | ||
"generate_release_notes": true | ||
} | ||
}] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,92 @@ | ||
# Utility collection for Deno | ||
![](https://github.com/dojyorin/deno_bit_utility/actions/workflows/test.yaml/badge.svg?branch=master) | ||
# **Simple Utility for Deno** | ||
![Actions-Test](https://github.com/dojyorin/deno_simple_utility/actions/workflows/test.yaml/badge.svg) | ||
![Actions-Release](https://github.com/dojyorin/deno_simple_utility/actions/workflows/release.yaml/badge.svg) | ||
|
||
A handy utility collection. | ||
|
||
# Example | ||
**BASE64 Binary** | ||
|
||
```ts | ||
const file = await Deno.readFile("/path/to/binary.bin"); | ||
|
||
const encoded = base64Encode(file); // BASE64 encoded string. | ||
const decoded = base64Decode(encoded); // Restored byte array. | ||
``` | ||
|
||
**DEFLATE Compress** | ||
|
||
```ts | ||
const file = await Deno.readFile("/path/to/binary.bin"); | ||
|
||
const encoded = await deflateEncode(file); // DEFLATE compressed byte array. | ||
const decoded = await deflateDecode(encoded); // Restored byte array. | ||
``` | ||
|
||
**Extended Fetch API** | ||
|
||
```ts | ||
const json = await fetchExtend("https://path/to/get", "json"); // Response as JSON. | ||
const bytes = await fetchExtend("https://path/to/get", "byte"); // Response as Uint8Array. | ||
``` | ||
|
||
**Minipack Archive** | ||
|
||
```ts | ||
const files = [ | ||
new File([await Deno.readFile("/path/to/binary.bin")], "binary.bin") | ||
]; | ||
|
||
const encoded = await minipackEncode(files); // Minipack archived byte array. | ||
const decoded = await minipackDecode(encoded); // Restored file object array. | ||
``` | ||
|
||
# Details | ||
It's basically a thin wrapper around Deno's functions to improve usability, but some features are original to this module. | ||
|
||
This section describes the original features of this module. | ||
|
||
## Minipack | ||
Minipack is a file archive format original to this module. | ||
|
||
It's structure is inspired by the famous "tar" and is minimal as an archive. | ||
|
||
Originally developed for browsers, the purpose was to aggregate multiple files input with the HTML File API into a single file. | ||
|
||
Therefore, there is no concept of directory or filesystem, and it's feature by simple structure that stores only the file body, file name, and hash value for verification. | ||
|
||
The actual binary structure looks like this: | ||
|
||
|Index|Type|Title|Size (Byte)| | ||
|:--|:--|:--|:--| | ||
|1|Header|HashValue|32| | ||
|2|Header|NameSize|1| | ||
|3|Header|BodySize|4| | ||
|4|Body|FileName|Max 255 (Defined in NameSize)| | ||
|5|Body|FileBody|Max 4294967295 (Defined in BodySize)| | ||
|
||
This is for one file and repeats for the number of files. | ||
|
||
# API | ||
## `Uint8Array base64Encode(data)` | ||
- `data` ... The byte array. | ||
|
||
## `Uint8Array base64Decode(data)` | ||
- `data` ... The BASE64 code. | ||
|
||
## `Promise<Uint8Array> deflateEncode(data)` | ||
- `data` ... The byte array. | ||
|
||
## `Promise<Uint8Array> deflateDecode(data)` | ||
- `data` ... The deflate compressed byte array. | ||
|
||
## `<FetchResponseType<T>> fetchExtend<T>(path, type, option)` | ||
- `path` ... Target URL. Since the query string is ignored, please specify it in the `option.query` property instead of writing it directly in the URL. | ||
- `type` ... The type you want to receive in the response. | ||
- `option` ... Fetch option. `window` is removed from `RequestInit` and `query` is added to write the query string. | ||
|
||
## `Promise<Uint8Array> minipackEncode(files)` | ||
- `files` ... Array of file object. | ||
|
||
## `Promise<File[]> minipackDecode(archive)` | ||
- `data` ... The minipack archived byte array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {assertEquals} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
export {assertEquals} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
export {serve} from "https://deno.land/[email protected]/http/mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export {type JsonValue} from "https://deno.land/std@0.159.0/encoding/json/stream.ts"; | ||
export {type JsonValue} from "https://deno.land/std@0.160.0/encoding/json/stream.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import "./test/base64.test.ts"; | ||
import "./test/deflate.test.ts"; | ||
import "./test/fetch_extend.test.ts"; | ||
import "./test/fetch.test.ts"; | ||
import "./test/minipack.test.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from "./src/base64.ts"; | ||
export * from "./src/deflate.ts"; | ||
export * from "./src/fetch_extend.ts"; | ||
export * from "./src/fetch.ts"; | ||
export * from "./src/minipack.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
async function transform(data:Uint8Array, ts:TransformStream<Uint8Array,Uint8Array>){ | ||
return new Uint8Array(await new Response(new Blob([data]).stream().pipeThrough(ts)).arrayBuffer()); | ||
} | ||
|
||
/** | ||
* Compresses raw binary in "deflate" format (RFC1951 compliant). | ||
* It does not include header information like "gzip" (RFC1952) or "zlib" (RFC1950) as it does purely "compression only". | ||
* @param data The byte buffer. | ||
* @param data The byte array. | ||
**/ | ||
export async function deflateEncode(data:ArrayBuffer){ | ||
return new Response(new Blob([data]).stream().pipeThrough(new CompressionStream("deflate-raw"))).arrayBuffer(); | ||
export async function deflateEncode(data:Uint8Array){ | ||
return await transform(data, new CompressionStream("deflate-raw")); | ||
} | ||
|
||
/** | ||
* Decompress "deflate" format (RFC1951 compliant) binary. | ||
* Binaries containing header information like "gzip" (RFC1952) or "zlib" (RFC1950) cannot be decompressed. | ||
* @param data The byte buffer. | ||
* @param data The byte array. | ||
**/ | ||
export async function deflateDecode(data:ArrayBuffer){ | ||
return new Response(new Blob([data]).stream().pipeThrough(new DecompressionStream("deflate-raw"))).arrayBuffer(); | ||
export async function deflateDecode(data:Uint8Array){ | ||
return await transform(data, new DecompressionStream("deflate-raw")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.