@ddunigma/node 2.0.2 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENCE +1 -1
- package/README.md +253 -79
- package/dist/cjs/encoders/Ddu64.d.ts +118 -1
- package/dist/cjs/encoders/Ddu64.js +521 -154
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/types/DduInterface.d.ts +53 -1
- package/dist/cjs/utils/CharsetBuilder.d.ts +129 -0
- package/dist/cjs/utils/CharsetBuilder.js +246 -0
- package/dist/cjs/utils/DduPipeline.d.ts +114 -0
- package/dist/cjs/utils/DduPipeline.js +229 -0
- package/dist/cjs/utils/DduStream.d.ts +64 -0
- package/dist/cjs/utils/DduStream.js +221 -0
- package/dist/cjs/utils/crypto.d.ts +30 -0
- package/dist/cjs/utils/crypto.js +84 -0
- package/dist/cjs/utils/index.d.ts +3 -0
- package/dist/cjs/utils/index.js +12 -0
- package/dist/mjs/encoders/Ddu64.d.ts +118 -1
- package/dist/mjs/encoders/Ddu64.js +534 -155
- package/dist/mjs/index.d.ts +2 -1
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/types/DduInterface.d.ts +53 -1
- package/dist/mjs/utils/CharsetBuilder.d.ts +129 -0
- package/dist/mjs/utils/CharsetBuilder.js +241 -0
- package/dist/mjs/utils/DduPipeline.d.ts +114 -0
- package/dist/mjs/utils/DduPipeline.js +223 -0
- package/dist/mjs/utils/DduStream.d.ts +64 -0
- package/dist/mjs/utils/DduStream.js +225 -0
- package/dist/mjs/utils/crypto.d.ts +30 -0
- package/dist/mjs/utils/crypto.js +78 -0
- package/dist/mjs/utils/index.d.ts +3 -0
- package/dist/mjs/utils/index.js +3 -0
- package/package.json +4 -3
package/LICENCE
CHANGED
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
Node.js implementation of [ddunigma](https://github.com/i3l3/ddunigma) (Python original)
|
|
8
8
|
|
|
9
|
+
커스텀 charset을 사용하는 Base64 스타일 인코더/디코더 라이브러리입니다.
|
|
10
|
+
|
|
9
11
|
### Credits
|
|
10
12
|
|
|
11
13
|
- Original Python Implementation by:
|
|
@@ -25,7 +27,7 @@ npm install @ddunigma/node
|
|
|
25
27
|
|
|
26
28
|
## Usage
|
|
27
29
|
|
|
28
|
-
###
|
|
30
|
+
### 기본 인코딩/디코딩
|
|
29
31
|
|
|
30
32
|
```typescript
|
|
31
33
|
import { Ddu64 } from "@ddunigma/node";
|
|
@@ -69,64 +71,224 @@ const encoder4 = new Ddu64(undefined, undefined, {
|
|
|
69
71
|
const text = "안녕하세요";
|
|
70
72
|
const encoded = encoder1.encode(text);
|
|
71
73
|
const decoded = encoder1.decode(encoded);
|
|
72
|
-
const decodedBuffer = encoder1.decodeToBuffer(encoded);
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
###
|
|
76
|
+
### 압축 인코딩
|
|
76
77
|
|
|
77
78
|
```typescript
|
|
78
79
|
import { Ddu64 } from "@ddunigma/node";
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"뜨", "뜩", "뜪", "뜫",
|
|
85
|
-
// ... 256개 문자
|
|
86
|
-
];
|
|
81
|
+
// 생성자에서 기본 압축 활성화
|
|
82
|
+
const encoder = new Ddu64(undefined, undefined, {
|
|
83
|
+
compress: true,
|
|
84
|
+
});
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
// 또는 encode 호출 시 압축 옵션 지정
|
|
87
|
+
const text = "반복되는 긴 텍스트...".repeat(100);
|
|
88
|
+
const encoded = encoder.encode(text, { compress: true });
|
|
89
|
+
const decoded = encoder.decode(encoded); // 자동으로 압축 해제
|
|
90
|
+
```
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
### URL-Safe 인코딩
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { Ddu64 } from "@ddunigma/node";
|
|
96
|
+
|
|
97
|
+
const encoder = new Ddu64(undefined, undefined, {
|
|
98
|
+
dduSetSymbol: DduSetSymbol.ONECHARSET,
|
|
99
|
+
urlSafe: true, // +, /, = 를 URL 안전 문자로 변환
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const encoded = encoder.encode("Hello World!");
|
|
103
|
+
// URL에서 안전하게 사용 가능한 문자열 반환
|
|
94
104
|
```
|
|
95
105
|
|
|
96
|
-
###
|
|
106
|
+
### 체크섬 (무결성 검증)
|
|
97
107
|
|
|
98
108
|
```typescript
|
|
99
109
|
import { Ddu64 } from "@ddunigma/node";
|
|
100
110
|
|
|
101
|
-
// 생성자에서 기본 압축 활성화
|
|
102
111
|
const encoder = new Ddu64(undefined, undefined, {
|
|
103
|
-
|
|
112
|
+
checksum: true, // CRC32 체크섬 활성화
|
|
104
113
|
});
|
|
105
114
|
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
const encoded = encoder.encode("Important data", { checksum: true });
|
|
116
|
+
const decoded = encoder.decode(encoded); // 자동으로 체크섬 검증
|
|
117
|
+
// 체크섬 불일치 시 에러 발생
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 암호화
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { Ddu64 } from "@ddunigma/node";
|
|
124
|
+
|
|
125
|
+
const encoder = new Ddu64(undefined, undefined, {
|
|
126
|
+
encryptionKey: "my-secret-key-123", // AES-256-GCM 암호화
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const encoded = encoder.encode("Secret message!");
|
|
130
|
+
const decoded = encoder.decode(encoded); // 자동으로 복호화
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 청크 분할
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { Ddu64 } from "@ddunigma/node";
|
|
137
|
+
|
|
138
|
+
const encoder = new Ddu64();
|
|
139
|
+
|
|
140
|
+
const encoded = encoder.encode(longData, {
|
|
141
|
+
chunkSize: 76, // 76자마다 분할
|
|
142
|
+
chunkSeparator: "\n", // 줄바꿈으로 구분
|
|
143
|
+
});
|
|
144
|
+
// 결과: "ABCDxyz...\nEFGHijk...\n..."
|
|
145
|
+
|
|
146
|
+
const decoded = encoder.decode(encoded); // 자동으로 줄바꿈 제거
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 비동기 인코딩/디코딩
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { Ddu64 } from "@ddunigma/node";
|
|
153
|
+
|
|
154
|
+
const encoder = new Ddu64();
|
|
155
|
+
|
|
156
|
+
// 비동기 인코딩 (이벤트 루프 블로킹 방지)
|
|
157
|
+
const encoded = await encoder.encodeAsync(largeData);
|
|
158
|
+
const decoded = await encoder.decodeAsync(encoded);
|
|
159
|
+
const buffer = await encoder.decodeToBufferAsync(encoded);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 진행률 콜백
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { Ddu64 } from "@ddunigma/node";
|
|
166
|
+
|
|
167
|
+
const encoder = new Ddu64();
|
|
168
|
+
|
|
169
|
+
encoder.encode(largeData, {
|
|
170
|
+
onProgress: (info) => {
|
|
171
|
+
console.log(`진행률: ${info.percent}%`);
|
|
172
|
+
console.log(`처리됨: ${info.processedBytes}/${info.totalBytes}`);
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 통계/분석
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { Ddu64 } from "@ddunigma/node";
|
|
181
|
+
|
|
182
|
+
const encoder = new Ddu64();
|
|
183
|
+
|
|
184
|
+
const stats = encoder.getStats("Test data", { compress: true });
|
|
185
|
+
console.log(stats);
|
|
186
|
+
// {
|
|
187
|
+
// originalSize: 9,
|
|
188
|
+
// encodedSize: 12,
|
|
189
|
+
// compressedSize: 17,
|
|
190
|
+
// compressionRatio: 1.89,
|
|
191
|
+
// expansionRatio: 1.33,
|
|
192
|
+
// charsetSize: 64,
|
|
193
|
+
// bitLength: 6
|
|
194
|
+
// }
|
|
110
195
|
```
|
|
111
196
|
|
|
112
|
-
### Zip Bomb 방어
|
|
197
|
+
### Zip Bomb 방어
|
|
113
198
|
|
|
114
199
|
```typescript
|
|
115
200
|
import { Ddu64 } from "@ddunigma/node";
|
|
116
201
|
|
|
117
|
-
// 디코딩/압축해제 크기 제한 설정 (기본값: 64MB)
|
|
118
202
|
const encoder = new Ddu64(undefined, undefined, {
|
|
119
203
|
maxDecodedBytes: 10 * 1024 * 1024, // 10MB
|
|
120
204
|
maxDecompressedBytes: 50 * 1024 * 1024, // 50MB
|
|
121
205
|
});
|
|
122
206
|
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
207
|
+
// 제한 초과 시 에러 발생
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## CharsetBuilder
|
|
213
|
+
|
|
214
|
+
커스텀 charset을 쉽게 생성할 수 있는 빌더 유틸리티입니다.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { CharsetBuilder } from "@ddunigma/node";
|
|
218
|
+
|
|
219
|
+
// 유니코드 범위에서 생성
|
|
220
|
+
const chars1 = CharsetBuilder.fromUnicodeRange(0x4e00, 0x4e3f).build();
|
|
221
|
+
|
|
222
|
+
// Base64 문자셋
|
|
223
|
+
const chars2 = CharsetBuilder.base64().build();
|
|
224
|
+
|
|
225
|
+
// 혼동 문자 제외 (0, O, 1, l, I 등)
|
|
226
|
+
const chars3 = CharsetBuilder.base64().excludeConfusing().build();
|
|
227
|
+
|
|
228
|
+
// 2의 제곱수로 제한
|
|
229
|
+
const chars4 = CharsetBuilder.fromString("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
230
|
+
.limitToPowerOfTwo()
|
|
231
|
+
.build(); // 32자
|
|
232
|
+
|
|
233
|
+
// URL 안전 문자만
|
|
234
|
+
const chars5 = CharsetBuilder.base64().excludeUrlUnsafe().build();
|
|
235
|
+
|
|
236
|
+
// 시드 기반 셔플
|
|
237
|
+
const chars6 = CharsetBuilder.base64().shuffle(12345).build();
|
|
238
|
+
|
|
239
|
+
// 패딩 문자와 함께 빌드
|
|
240
|
+
const { charset, padding } = CharsetBuilder.base64().buildWithPadding();
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## DduPipeline
|
|
246
|
+
|
|
247
|
+
다단계 인코딩/암호화/압축을 조합할 수 있는 파이프라인 빌더입니다.
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { DduPipeline, Ddu64 } from "@ddunigma/node";
|
|
251
|
+
|
|
252
|
+
const encoder = new Ddu64();
|
|
253
|
+
|
|
254
|
+
// 압축 → 암호화 → 인코딩 파이프라인
|
|
255
|
+
const pipeline = new DduPipeline()
|
|
256
|
+
.compress()
|
|
257
|
+
.encrypt("my-secret-key")
|
|
258
|
+
.encode(encoder);
|
|
259
|
+
|
|
260
|
+
const encoded = pipeline.processToString("Hello World!");
|
|
261
|
+
|
|
262
|
+
// 역순 파이프라인으로 복원
|
|
263
|
+
const decoded = pipeline.reverse().processToString(encoded);
|
|
127
264
|
```
|
|
128
265
|
|
|
129
|
-
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 스트림 지원
|
|
269
|
+
|
|
270
|
+
대용량 파일 처리를 위한 스트림 인코딩/디코딩을 지원합니다.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { Ddu64, createEncodeStream, createDecodeStream } from "@ddunigma/node";
|
|
274
|
+
import fs from "fs";
|
|
275
|
+
|
|
276
|
+
const encoder = new Ddu64();
|
|
277
|
+
|
|
278
|
+
// 인코딩 스트림
|
|
279
|
+
fs.createReadStream("input.bin")
|
|
280
|
+
.pipe(createEncodeStream(encoder))
|
|
281
|
+
.pipe(fs.createWriteStream("output.txt"));
|
|
282
|
+
|
|
283
|
+
// 디코딩 스트림
|
|
284
|
+
fs.createReadStream("output.txt")
|
|
285
|
+
.pipe(createDecodeStream(encoder))
|
|
286
|
+
.pipe(fs.createWriteStream("restored.bin"));
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## API Reference
|
|
130
292
|
|
|
131
293
|
### `new Ddu64(dduChar?, paddingChar?, options?)`
|
|
132
294
|
|
|
@@ -134,84 +296,96 @@ const decoded = encoder.decode(encoded, {
|
|
|
134
296
|
|
|
135
297
|
**Parameters:**
|
|
136
298
|
|
|
137
|
-
| Parameter
|
|
138
|
-
|
|
139
|
-
| `dduChar`
|
|
140
|
-
| `paddingChar` | `string`
|
|
141
|
-
| `options`
|
|
299
|
+
| Parameter | Type | Description |
|
|
300
|
+
| ------------- | ----------------------- | ------------------------ |
|
|
301
|
+
| `dduChar` | `string \| string[]` | charset 문자열 또는 배열 |
|
|
302
|
+
| `paddingChar` | `string` | 패딩 문자 |
|
|
303
|
+
| `options` | `DduConstructorOptions` | 옵션 객체 |
|
|
142
304
|
|
|
143
305
|
**DduConstructorOptions:**
|
|
144
306
|
|
|
145
|
-
| Option
|
|
146
|
-
|
|
147
|
-
| `dduSetSymbol`
|
|
148
|
-
| `encoding`
|
|
149
|
-
| `usePowerOfTwo`
|
|
150
|
-
| `useBuildErrorReturn`
|
|
151
|
-
| `compress`
|
|
152
|
-
| `maxDecodedBytes`
|
|
153
|
-
| `maxDecompressedBytes` | `number`
|
|
307
|
+
| Option | Type | Default | Description |
|
|
308
|
+
| ---------------------- | ---------------- | ----------- | --------------------------- |
|
|
309
|
+
| `dduSetSymbol` | `DduSetSymbol` | `DDU` | 미리 정의된 charset 심볼 |
|
|
310
|
+
| `encoding` | `BufferEncoding` | `'utf-8'` | 문자열 인코딩 |
|
|
311
|
+
| `usePowerOfTwo` | `boolean` | `true` | 2의 제곱수 강제 여부 |
|
|
312
|
+
| `useBuildErrorReturn` | `boolean` | `false` | 에러 발생 시 throw 여부 |
|
|
313
|
+
| `compress` | `boolean` | `false` | 기본 압축 활성화 |
|
|
314
|
+
| `maxDecodedBytes` | `number` | `67108864` | 최대 디코딩 바이트 (64MB) |
|
|
315
|
+
| `maxDecompressedBytes` | `number` | `67108864` | 최대 압축해제 바이트 (64MB) |
|
|
316
|
+
| `urlSafe` | `boolean` | `false` | URL-Safe 모드 |
|
|
317
|
+
| `encryptionKey` | `string` | `undefined` | AES-256-GCM 암호화 키 |
|
|
318
|
+
| `checksum` | `boolean` | `false` | CRC32 체크섬 활성화 |
|
|
319
|
+
| `chunkSize` | `number` | `undefined` | 청크 분할 크기 |
|
|
320
|
+
| `chunkSeparator` | `string` | `'\n'` | 청크 구분자 |
|
|
154
321
|
|
|
155
322
|
### `encode(data, options?): string`
|
|
156
323
|
|
|
157
324
|
데이터를 인코딩합니다.
|
|
158
325
|
|
|
159
|
-
**
|
|
160
|
-
|
|
161
|
-
| Parameter | Type | Description |
|
|
162
|
-
|-----------|------|-------------|
|
|
163
|
-
| `data` | `string \| Buffer` | 인코딩할 데이터 |
|
|
164
|
-
| `options.compress` | `boolean` | 압축 사용 여부 |
|
|
326
|
+
**DduOptions:**
|
|
165
327
|
|
|
166
|
-
|
|
328
|
+
| Option | Type | Description |
|
|
329
|
+
| ---------------- | ---------- | ---------------- |
|
|
330
|
+
| `compress` | `boolean` | 압축 사용 여부 |
|
|
331
|
+
| `checksum` | `boolean` | 체크섬 추가 여부 |
|
|
332
|
+
| `chunkSize` | `number` | 청크 분할 크기 |
|
|
333
|
+
| `chunkSeparator` | `string` | 청크 구분자 |
|
|
334
|
+
| `onProgress` | `function` | 진행률 콜백 |
|
|
167
335
|
|
|
168
336
|
### `decode(encoded, options?): string`
|
|
169
337
|
|
|
170
338
|
인코딩된 문자열을 디코딩합니다.
|
|
171
339
|
|
|
172
|
-
|
|
340
|
+
### `decodeToBuffer(encoded, options?): Buffer`
|
|
173
341
|
|
|
174
|
-
|
|
175
|
-
|-----------|------|-------------|
|
|
176
|
-
| `encoded` | `string` | 인코딩된 문자열 |
|
|
177
|
-
| `options.maxDecodedBytes` | `number` | 최대 디코딩 바이트 |
|
|
178
|
-
| `options.maxDecompressedBytes` | `number` | 최대 압축해제 바이트 |
|
|
342
|
+
인코딩된 문자열을 Buffer로 직접 디코딩합니다.
|
|
179
343
|
|
|
180
|
-
|
|
344
|
+
### `encodeAsync(data, options?): Promise<string>`
|
|
181
345
|
|
|
182
|
-
|
|
346
|
+
비동기로 데이터를 인코딩합니다.
|
|
183
347
|
|
|
184
|
-
|
|
348
|
+
### `decodeAsync(encoded, options?): Promise<string>`
|
|
185
349
|
|
|
186
|
-
|
|
350
|
+
비동기로 데이터를 디코딩합니다.
|
|
187
351
|
|
|
188
|
-
|
|
352
|
+
### `decodeToBufferAsync(encoded, options?): Promise<Buffer>`
|
|
189
353
|
|
|
190
|
-
|
|
354
|
+
비동기로 Buffer로 디코딩합니다.
|
|
191
355
|
|
|
192
|
-
|
|
356
|
+
### `getStats(data, options?): DduEncodeStats`
|
|
193
357
|
|
|
194
|
-
|
|
358
|
+
인코딩 통계 정보를 반환합니다.
|
|
195
359
|
|
|
196
360
|
```typescript
|
|
197
361
|
{
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
defaultMaxDecodedBytes: number;
|
|
206
|
-
defaultMaxDecompressedBytes: number;
|
|
362
|
+
originalSize: number; // 원본 데이터 크기
|
|
363
|
+
encodedSize: number; // 인코딩된 문자열 길이
|
|
364
|
+
compressedSize?: number; // 압축된 크기
|
|
365
|
+
compressionRatio?: number; // 압축률 (0-1)
|
|
366
|
+
expansionRatio: number; // 인코딩 확장 비율
|
|
367
|
+
charsetSize: number; // charset 크기
|
|
368
|
+
bitLength: number; // 비트 길이
|
|
207
369
|
}
|
|
208
370
|
```
|
|
209
371
|
|
|
372
|
+
### `getCharSetInfo(): CharSetInfo`
|
|
373
|
+
|
|
374
|
+
현재 인코더의 charset 정보를 반환합니다.
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
210
378
|
## DduSetSymbol
|
|
211
379
|
|
|
212
|
-
| Symbol
|
|
213
|
-
|
|
214
|
-
| `DDU`
|
|
215
|
-
| `ONECHARSET`
|
|
216
|
-
| `TWOCHARSET`
|
|
217
|
-
| `THREECHARSET` | 32768
|
|
380
|
+
| Symbol | 문자 수 | 비트 길이 | 설명 |
|
|
381
|
+
| -------------- | ------- | --------- | ------------------------- |
|
|
382
|
+
| `DDU` | 8 | 3 | 한글 + 특수문자 기본 세트 |
|
|
383
|
+
| `ONECHARSET` | 64 | 6 | 영문 + 숫자 + 특수문자 |
|
|
384
|
+
| `TWOCHARSET` | 1024 | 10 | 2글자 조합 세트 |
|
|
385
|
+
| `THREECHARSET` | 32768 | 15 | 3글자 조합 세트 |
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## License
|
|
390
|
+
|
|
391
|
+
BSD-2-Clause
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseDdu } from "../base/BaseDdu";
|
|
2
|
-
import { DduConstructorOptions, DduOptions } from "../types";
|
|
2
|
+
import { DduConstructorOptions, DduOptions, DduEncodeStats } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* 커스텀 charset을 사용하는 Base64 스타일 인코더
|
|
5
5
|
*
|
|
@@ -50,6 +50,18 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
50
50
|
private readonly fastAsciiLookup;
|
|
51
51
|
/** ASCII 룩업 사용 여부 */
|
|
52
52
|
private readonly useAsciiLookup;
|
|
53
|
+
/** URL-Safe 모드 여부 */
|
|
54
|
+
private readonly urlSafe;
|
|
55
|
+
/** 암호화 키 해시 (AES-256용 32바이트) */
|
|
56
|
+
private readonly encryptionKeyHash;
|
|
57
|
+
/** 기본 체크섬 사용 여부 */
|
|
58
|
+
private readonly defaultChecksum;
|
|
59
|
+
/** 기본 청크 크기 */
|
|
60
|
+
private readonly defaultChunkSize;
|
|
61
|
+
/** 기본 청크 구분자 */
|
|
62
|
+
private readonly defaultChunkSeparator;
|
|
63
|
+
/** 기본 압축 레벨 (1~9) */
|
|
64
|
+
private readonly defaultCompressionLevel;
|
|
53
65
|
/**
|
|
54
66
|
* Ddu64 인코더 인스턴스를 생성합니다.
|
|
55
67
|
*
|
|
@@ -75,13 +87,23 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
75
87
|
* @param input - 인코딩할 문자열 또는 Buffer
|
|
76
88
|
* @param options - 인코딩 옵션
|
|
77
89
|
* @param options.compress - 압축 사용 여부 (기본값: 생성자 설정)
|
|
90
|
+
* @param options.checksum - 체크섬 추가 여부
|
|
91
|
+
* @param options.chunkSize - 청크 분할 크기
|
|
92
|
+
* @param options.chunkSeparator - 청크 구분자
|
|
93
|
+
* @param options.onProgress - 진행률 콜백
|
|
78
94
|
* @returns 인코딩된 문자열
|
|
79
95
|
*
|
|
80
96
|
* @example
|
|
81
97
|
* encoder.encode("Hello World!");
|
|
82
98
|
* encoder.encode(buffer, { compress: true });
|
|
99
|
+
* encoder.encode(data, { checksum: true, chunkSize: 76 });
|
|
83
100
|
*/
|
|
84
101
|
encode(input: Buffer | string, options?: DduOptions): string;
|
|
102
|
+
/**
|
|
103
|
+
* 인코딩 핵심 로직. encode()와 getStats()가 공유합니다.
|
|
104
|
+
* 압축 크기 등 메타데이터도 함께 반환하여 중복 deflateSync 호출을 방지합니다.
|
|
105
|
+
*/
|
|
106
|
+
private encodeInternal;
|
|
85
107
|
/**
|
|
86
108
|
* 인코딩된 문자열을 Buffer로 디코딩합니다.
|
|
87
109
|
*
|
|
@@ -89,11 +111,13 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
89
111
|
* @param options - 디코딩 옵션
|
|
90
112
|
* @param options.maxDecodedBytes - 최대 디코딩 바이트 수
|
|
91
113
|
* @param options.maxDecompressedBytes - 최대 압축해제 바이트 수
|
|
114
|
+
* @param options.onProgress - 진행률 콜백
|
|
92
115
|
* @returns 디코딩된 Buffer
|
|
93
116
|
*
|
|
94
117
|
* @throws 잘못된 문자가 포함된 경우
|
|
95
118
|
* @throws 패딩 형식이 잘못된 경우
|
|
96
119
|
* @throws 크기 제한 초과 시
|
|
120
|
+
* @throws 체크섬 불일치 시
|
|
97
121
|
*/
|
|
98
122
|
decodeToBuffer(input: string, options?: DduOptions): Buffer;
|
|
99
123
|
/**
|
|
@@ -121,7 +145,89 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
121
145
|
defaultCompress: boolean;
|
|
122
146
|
defaultMaxDecodedBytes: number;
|
|
123
147
|
defaultMaxDecompressedBytes: number;
|
|
148
|
+
urlSafe: boolean;
|
|
149
|
+
hasEncryptionKey: boolean;
|
|
150
|
+
defaultChecksum: boolean;
|
|
151
|
+
defaultChunkSize: number | undefined;
|
|
124
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* 인코딩 통계 정보를 반환합니다.
|
|
155
|
+
*
|
|
156
|
+
* @param input - 분석할 데이터
|
|
157
|
+
* @param options - 인코딩 옵션
|
|
158
|
+
* @returns 통계 정보 객체
|
|
159
|
+
*/
|
|
160
|
+
getStats(input: Buffer | string, options?: DduOptions): DduEncodeStats;
|
|
161
|
+
/**
|
|
162
|
+
* 비동기 인코딩을 수행합니다.
|
|
163
|
+
*
|
|
164
|
+
* 내부적으로 동기 encode()를 setImmediate로 이벤트 루프에 양보한 뒤 실행합니다.
|
|
165
|
+
* 호출자가 즉시 블로킹되지 않도록 보장하지만, 인코딩 자체는 단일 동기 작업으로
|
|
166
|
+
* 수행되므로 대용량 데이터(수 MB 이상) 처리 시 이벤트 루프가 블로킹될 수 있습니다.
|
|
167
|
+
* 대용량 처리가 필요한 경우 스트림 API(createEncodeStream) 사용을 권장합니다.
|
|
168
|
+
*
|
|
169
|
+
* @param input - 인코딩할 데이터
|
|
170
|
+
* @param options - 인코딩 옵션
|
|
171
|
+
* @returns 인코딩된 문자열 Promise
|
|
172
|
+
*/
|
|
173
|
+
encodeAsync(input: Buffer | string, options?: DduOptions): Promise<string>;
|
|
174
|
+
/**
|
|
175
|
+
* 비동기 디코딩을 수행합니다.
|
|
176
|
+
*
|
|
177
|
+
* 내부적으로 동기 decode()를 setImmediate로 이벤트 루프에 양보한 뒤 실행합니다.
|
|
178
|
+
* 대용량 처리가 필요한 경우 스트림 API(createDecodeStream) 사용을 권장합니다.
|
|
179
|
+
*
|
|
180
|
+
* @param input - 디코딩할 인코딩된 문자열
|
|
181
|
+
* @param options - 디코딩 옵션
|
|
182
|
+
* @returns 디코딩된 문자열 Promise
|
|
183
|
+
*/
|
|
184
|
+
decodeAsync(input: string, options?: DduOptions): Promise<string>;
|
|
185
|
+
/**
|
|
186
|
+
* 비동기 디코딩을 Buffer로 수행합니다.
|
|
187
|
+
*
|
|
188
|
+
* 내부적으로 동기 decodeToBuffer()를 setImmediate로 이벤트 루프에 양보한 뒤 실행합니다.
|
|
189
|
+
* 대용량 처리가 필요한 경우 스트림 API(createDecodeStream) 사용을 권장합니다.
|
|
190
|
+
*
|
|
191
|
+
* @param input - 디코딩할 인코딩된 문자열
|
|
192
|
+
* @param options - 디코딩 옵션
|
|
193
|
+
* @returns 디코딩된 Buffer Promise
|
|
194
|
+
*/
|
|
195
|
+
decodeToBufferAsync(input: string, options?: DduOptions): Promise<Buffer>;
|
|
196
|
+
/**
|
|
197
|
+
* 문자열을 URL-Safe 형식으로 변환합니다.
|
|
198
|
+
* 단일 정규식 패스로 처리하여 split/join 3회 반복 대비 메모리/속도 개선
|
|
199
|
+
*/
|
|
200
|
+
private toUrlSafe;
|
|
201
|
+
/**
|
|
202
|
+
* URL-Safe 형식에서 원래 형식으로 복원합니다.
|
|
203
|
+
*/
|
|
204
|
+
private fromUrlSafe;
|
|
205
|
+
/**
|
|
206
|
+
* CRC32 체크섬을 계산합니다. (룩업 테이블 사용)
|
|
207
|
+
*/
|
|
208
|
+
private calculateCRC32;
|
|
209
|
+
/**
|
|
210
|
+
* 인코딩된 문자열에서 체크섬을 추출합니다.
|
|
211
|
+
*/
|
|
212
|
+
private extractChecksum;
|
|
213
|
+
/**
|
|
214
|
+
* 문자열을 청크로 분할합니다.
|
|
215
|
+
*/
|
|
216
|
+
private splitIntoChunks;
|
|
217
|
+
/**
|
|
218
|
+
* 청크 구분자를 제거합니다.
|
|
219
|
+
* 줄바꿈(\r, \n)과 인스턴스에 설정된 청크 구분자만 제거합니다.
|
|
220
|
+
* 공백/탭 등은 charset에 포함될 수 있으므로 제거하지 않습니다.
|
|
221
|
+
*/
|
|
222
|
+
private removeChunks;
|
|
223
|
+
/**
|
|
224
|
+
* 데이터를 AES-256-GCM으로 암호화합니다.
|
|
225
|
+
*/
|
|
226
|
+
private encryptData;
|
|
227
|
+
/**
|
|
228
|
+
* AES-256-GCM으로 암호화된 데이터를 복호화합니다.
|
|
229
|
+
*/
|
|
230
|
+
private decryptData;
|
|
125
231
|
/**
|
|
126
232
|
* 옵션 값을 정규화합니다.
|
|
127
233
|
*/
|
|
@@ -140,6 +246,9 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
140
246
|
private inflateWithLimit;
|
|
141
247
|
/**
|
|
142
248
|
* 인코딩된 문자열의 푸터(패딩 정보)를 파싱합니다.
|
|
249
|
+
*
|
|
250
|
+
* 푸터 형식: {encodedData}{paddingChar}[ELYSIA][ENC]{digits}
|
|
251
|
+
* 끝에서부터 역순으로 파싱하여 paddingChar가 숫자인 경우도 안전하게 처리합니다.
|
|
143
252
|
*/
|
|
144
253
|
private parseFooter;
|
|
145
254
|
/**
|
|
@@ -178,6 +287,14 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
178
287
|
* charset을 가져오거나 에러를 발생시킵니다.
|
|
179
288
|
*/
|
|
180
289
|
private getCharSetOrThrow;
|
|
290
|
+
/**
|
|
291
|
+
* URL-Safe 모드 시 charset/padding이 역변환 대상 문자를 포함하지 않는지 검증합니다.
|
|
292
|
+
* 역변환 대상 문자("-", "_", ".")가 charset이나 padding에 있으면
|
|
293
|
+
* fromUrlSafe 시 해당 문자가 "+", "/", "="로 변환되어 데이터가 손상됩니다.
|
|
294
|
+
*
|
|
295
|
+
* @returns URL-Safe 모드를 활성화해도 안전한 경우 true
|
|
296
|
+
*/
|
|
297
|
+
private isUrlSafeCompatible;
|
|
181
298
|
/**
|
|
182
299
|
* 커스텀 charset의 조합 중복을 검증합니다.
|
|
183
300
|
*/
|