s3mini 0.7.1 → 0.8.0

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/src/utils.ts CHANGED
@@ -3,7 +3,7 @@ import type { XmlValue, XmlMap, ListBucketResponse, ErrorWithCode } from './type
3
3
 
4
4
  const ENCODR = new TextEncoder();
5
5
  const chunkSize = 0x8000; // 32KB chunks
6
- const HEXS = '0123456789abcdef';
6
+ const HEX_CHARS = new Uint8Array([48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102]);
7
7
 
8
8
  export const getByteSize = (data: unknown): number => {
9
9
  if (typeof data === 'string') {
@@ -23,13 +23,15 @@ export const getByteSize = (data: unknown): number => {
23
23
  * @param {ArrayBuffer} buffer The raw bytes.
24
24
  * @returns {string} Hexadecimal string
25
25
  */
26
+
26
27
  export const hexFromBuffer = (buffer: ArrayBuffer): string => {
27
28
  const bytes = new Uint8Array(buffer);
28
- let hex = '';
29
- for (const byte of bytes) {
30
- hex += HEXS[byte >> 4]! + HEXS[byte & 0x0f]!;
29
+ const hex = new Uint8Array(bytes.length * 2);
30
+ for (let i = 0, j = 0; i < bytes.length; i++) {
31
+ hex[j++] = HEX_CHARS[bytes[i]! >> 4]!;
32
+ hex[j++] = HEX_CHARS[bytes[i]! & 0x0f]!;
31
33
  }
32
- return hex;
34
+ return String.fromCharCode(...hex);
33
35
  };
34
36
 
35
37
  /**
@@ -153,6 +155,38 @@ export const parseXml = (input: string): XmlValue => {
153
155
  return Object.keys(result).length > 0 ? result : unescapeXml(xmlContent.trim());
154
156
  };
155
157
 
158
+ // export const parseXml = (input: string): XmlValue => {
159
+ // const xml = input.replace(/<\?xml[^?]*\?>\s*/, '');
160
+ // const result: XmlMap = {};
161
+ // let i = 0;
162
+ // const len = xml.length;
163
+
164
+ // while (i < len) {
165
+ // const tagStart = xml.indexOf('<', i);
166
+ // if (tagStart === -1 || xml[tagStart + 1] === '/') {
167
+ // break;
168
+ // }
169
+
170
+ // const tagEnd = xml.indexOf('>', tagStart);
171
+ // const tag = xml.slice(tagStart + 1, tagEnd);
172
+ // const closeTag = `</${tag}>`;
173
+ // const closeIdx = xml.indexOf(closeTag, tagEnd);
174
+
175
+ // if (closeIdx === -1) {
176
+ // i = tagEnd + 1;
177
+ // continue;
178
+ // }
179
+
180
+ // const inner = xml.slice(tagEnd + 1, closeIdx);
181
+ // const node = inner.includes('<') ? parseXml(inner) : unescapeXml(inner);
182
+
183
+ // const cur = result[tag];
184
+ // result[tag] = cur === undefined ? node : Array.isArray(cur) ? [...cur, node] : [cur, node];
185
+ // i = closeIdx + closeTag.length;
186
+ // }
187
+ // return Object.keys(result).length ? result : unescapeXml(xml.trim());
188
+ // };
189
+
156
190
  /**
157
191
  * Encode a character as a URI percent-encoded hex value
158
192
  * @param c Character to encode