@@ -32,60 +32,6 @@ export async function decompressFromBase64(input: string): Promise<string> {
3232 return textDecoder . decode ( decompressed ) ;
3333}
3434
35- export async function compressToUTF16 ( input : string ) : Promise < string > {
36- const upstream = createUpstream ( textEncoder . encode ( input ) ) ;
37- const compression = new CompressionStream ( "deflate" ) ;
38- const stream = upstream . pipeThrough ( compression ) ;
39- const compressed = await new Response ( stream ) . arrayBuffer ( ) ;
40-
41- let compressedBytes = new Uint8Array ( compressed ) ;
42-
43- if ( compressedBytes . length % 2 !== 0 ) {
44- const paddedBytes = new Uint8Array ( compressedBytes . length + 1 ) ;
45- paddedBytes . set ( compressedBytes ) ;
46- paddedBytes [ compressedBytes . length ] = 0 ; // 奇数個配列の場合、最後のバイトに 0 をパディング
47- compressedBytes = paddedBytes ;
48- }
49-
50- const compressedUint16Array = new Uint16Array ( compressedBytes . buffer ) ;
51- return String . fromCharCode ( ...compressedUint16Array ) ;
52- }
53-
54- export async function decompressFromUTF16 ( input : string ) : Promise < string > {
55- const compressedUint16Array = new Uint16Array (
56- input . split ( "" ) . map ( ( c ) => c . charCodeAt ( 0 ) ) ,
57- ) ;
58- let compressedBytes = new Uint8Array ( compressedUint16Array . buffer ) ;
59-
60- if ( compressedBytes [ compressedBytes . length - 1 ] === 0 ) {
61- compressedBytes = compressedBytes . slice ( 0 , compressedBytes . length - 1 ) ; // パディングされた 0 を削除
62- }
63-
64- const upstream = createUpstream ( compressedBytes ) ;
65- const decompression = new DecompressionStream ( "deflate" ) ;
66- const stream = upstream . pipeThrough ( decompression ) ;
67- const decompressed = await new Response ( stream ) . arrayBuffer ( ) ;
68- return textDecoder . decode ( decompressed ) ;
69- }
70-
71- export async function compressToUint8Array ( input : string ) : Promise < Uint8Array > {
72- const upstream = createUpstream ( textEncoder . encode ( input ) ) ;
73- const compression = new CompressionStream ( "deflate" ) ;
74- const stream = upstream . pipeThrough ( compression ) ;
75- const compressed = await new Response ( stream ) . arrayBuffer ( ) ;
76- return new Uint8Array ( compressed ) ;
77- }
78-
79- export async function decompressFromUint8Array (
80- input : Uint8Array ,
81- ) : Promise < string > {
82- const upstream = createUpstream ( input ) ;
83- const decompression = new DecompressionStream ( "deflate" ) ;
84- const stream = upstream . pipeThrough ( decompression ) ;
85- const decompressed = await new Response ( stream ) . arrayBuffer ( ) ;
86- return textDecoder . decode ( decompressed ) ;
87- }
88-
8935export async function compressToEncodedURIComponent (
9036 input : string ,
9137) : Promise < string > {
0 commit comments