Skip to content

Commit

Permalink
change interface name
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jul 4, 2024
1 parent fbd3979 commit 931c3c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/deno_ext/smtp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {createTransport} from "../../deps.ts";
import {type DataMap} from "../pure/minipack.ts";
import {type DataEntry} from "../pure/minipack.ts";

/**
* E-MAIL message.
Expand All @@ -11,7 +11,7 @@ export interface MailMessage {
body: string;
cc?: string[];
bcc?: string[];
files?: DataMap[];
files?: DataEntry[];
}

/**
Expand Down
26 changes: 13 additions & 13 deletions src/pure/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface ResponseType {
interface ReturnTypeMap {
"text": string;
"json": unknown;
"form": FormData;
Expand Down Expand Up @@ -29,7 +29,7 @@ export interface FetchInit extends Omit<RequestInit, "integrity" | "window"> {
* const response = await fetchExtend("./asset", "byte");
* ```
*/
export async function fetchExtend<T extends keyof ResponseType>(path: string, type: T, option?: FetchInit): Promise<ResponseType[T]> {
export async function fetchExtend<T extends keyof ReturnTypeMap>(path: string, type: T, option?: FetchInit): Promise<ReturnTypeMap[T]> {
const u = new URL(path, globalThis?.location?.href);
u.hash = "";

Expand All @@ -52,17 +52,17 @@ export async function fetchExtend<T extends keyof ResponseType>(path: string, ty
});

switch(type) {
case "text": return <ResponseType[T]>await response.text();
case "json": return <ResponseType[T]>await response.json();
case "form": return <ResponseType[T]>await response.formData();
case "byte": return <ResponseType[T]>new Uint8Array(await response.arrayBuffer());
case "buffer": return <ResponseType[T]>await response.arrayBuffer();
case "blob": return <ResponseType[T]>await response.blob();
case "stream": return <ResponseType[T]>(response.body ?? undefined);
case "ok": await response.body?.cancel(); return <ResponseType[T]>response.ok;
case "code": await response.body?.cancel(); return <ResponseType[T]>response.status;
case "header": await response.body?.cancel(); return <ResponseType[T]>response.headers;
case "response": return <ResponseType[T]>response;
case "text": return <ReturnTypeMap[T]> await response.text();
case "json": return <ReturnTypeMap[T]> await response.json();
case "form": return <ReturnTypeMap[T]> await response.formData();
case "byte": return <ReturnTypeMap[T]> new Uint8Array(await response.arrayBuffer());
case "buffer": return <ReturnTypeMap[T]> await response.arrayBuffer();
case "blob": return <ReturnTypeMap[T]> await response.blob();
case "stream": return <ReturnTypeMap[T]> (response.body ?? undefined);
case "ok": await response.body?.cancel(); return <ReturnTypeMap[T]> response.ok;
case "code": await response.body?.cancel(); return <ReturnTypeMap[T]> response.status;
case "header": await response.body?.cancel(); return <ReturnTypeMap[T]> response.headers;
case "response": return <ReturnTypeMap[T]> response;
default: throw new Error();
}
}
8 changes: 4 additions & 4 deletions src/pure/minipack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const BODY_SIZE = 4;
/**
* Simple name and body pair.
*/
export interface DataMap {
export interface DataEntry {
name: string;
body: Uint8Array;
}
Expand All @@ -24,7 +24,7 @@ export interface DataMap {
* const decode = minipackDecode(encode);
* ```
*/
export function minipackEncode(files: DataMap[]): Uint8Array {
export function minipackEncode(files: DataEntry[]): Uint8Array {
const archive = new Uint8Array(files.reduce((size, {name, body}) => size + NAME_SIZE + BODY_SIZE + textEncode(name).byteLength + body.byteLength, 0));

let i = 0;
Expand Down Expand Up @@ -60,8 +60,8 @@ export function minipackEncode(files: DataMap[]): Uint8Array {
* const decode = minipackDecode(encode);
* ```
*/
export function minipackDecode(archive: Uint8Array): DataMap[] {
const files: DataMap[] = [];
export function minipackDecode(archive: Uint8Array): DataEntry[] {
const files: DataEntry[] = [];

for(let i = 0; i < archive.byteLength;) {
const ns = new DataView(archive.buffer, i).getUint8(0);
Expand Down
8 changes: 4 additions & 4 deletions src/pure_ext/zip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ZipReader, ZipWriter, Uint8ArrayReader, Uint8ArrayWriter} from "../../deps.pure.ts";
import {type DataMap} from "../pure/minipack.ts";
import {type DataEntry} from "../pure/minipack.ts";

/**
* Convert from named binary to ZIP archive.
Expand All @@ -14,7 +14,7 @@ import {type DataMap} from "../pure/minipack.ts";
* const files = await zipDecode(zip);
* ```
*/
export async function zipEncode(files: DataMap[], pw?: string, weak?: boolean): Promise<Uint8Array> {
export async function zipEncode(files: DataEntry[], pw?: string, weak?: boolean): Promise<Uint8Array> {
const zip = new ZipWriter(new Uint8ArrayWriter(), {
password: pw,
zipCrypto: weak
Expand Down Expand Up @@ -42,8 +42,8 @@ export async function zipEncode(files: DataMap[], pw?: string, weak?: boolean):
* const files = await zipDecode(zip);
* ```
*/
export async function zipDecode(archive: Uint8Array, pw?: string, encode?: string): Promise<DataMap[]> {
const files: DataMap[] = [];
export async function zipDecode(archive: Uint8Array, pw?: string, encode?: string): Promise<DataEntry[]> {
const files: DataEntry[] = [];
const zip = new ZipReader(new Uint8ArrayReader(archive), {
useWebWorkers: false,
filenameEncoding: encode,
Expand Down

0 comments on commit 931c3c7

Please sign in to comment.