@zenfs/core 0.5.4 → 0.5.6

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/dist/utils.js CHANGED
@@ -97,105 +97,23 @@ export const setImmediate = typeof globalThis.setImmediate == 'function' ? globa
97
97
  * Encodes a string into a buffer
98
98
  * @internal
99
99
  */
100
- export function encode(input, encoding = 'utf8') {
100
+ export function encode(input) {
101
101
  if (typeof input != 'string') {
102
102
  throw new ApiError(ErrorCode.EINVAL, 'Can not encode a non-string');
103
103
  }
104
- switch (encoding) {
105
- case 'ascii':
106
- case 'latin1':
107
- case 'binary':
108
- return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
109
- case 'utf8':
110
- case 'utf-8':
111
- return new Uint8Array(Array.from(input).flatMap(char => {
112
- const code = char.charCodeAt(0);
113
- if (code < 0x80) {
114
- return code;
115
- }
116
- const a = (code & 0x3f) | 0x80;
117
- if (code < 0x800) {
118
- return [(code >> 6) | 0xc0, a];
119
- }
120
- const b = ((code >> 6) & 0x3f) | 0x80;
121
- if (code < 0x10000) {
122
- return [(code >> 12) | 0xe0, b, a];
123
- }
124
- return [(code >> 18) | 0xf0, ((code >> 12) & 0x3f) | 0x80, b, a];
125
- }));
126
- case 'base64':
127
- return encode(atob(input), 'utf-8');
128
- case 'base64url':
129
- return encode(input.replace('_', '/').replace('-', '+'), 'base64');
130
- case 'hex':
131
- return new Uint8Array(input.match(/.{1,2}/g).map(e => parseInt(e, 16)));
132
- case 'utf16le':
133
- case 'ucs2':
134
- case 'ucs-2':
135
- const u16 = new Uint16Array(new ArrayBuffer(input.length * 2));
136
- for (let i = 0; i < input.length; i++) {
137
- u16[i] = input.charCodeAt(i);
138
- }
139
- return new Uint8Array(u16.buffer);
140
- default:
141
- throw new ApiError(ErrorCode.EINVAL, 'Invalid encoding: ' + encoding);
142
- }
104
+ return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
143
105
  }
144
106
  /**
145
107
  * Decodes a string from a buffer
146
108
  * @internal
147
109
  */
148
- export function decode(input, encoding = 'utf8') {
110
+ export function decode(input) {
149
111
  if (!(input instanceof Uint8Array)) {
150
112
  throw new ApiError(ErrorCode.EINVAL, 'Can not decode a non-Uint8Array');
151
113
  }
152
- switch (encoding) {
153
- case 'ascii':
154
- case 'latin1':
155
- case 'binary':
156
- return Array.from(input)
157
- .map(char => String.fromCharCode(char))
158
- .join('');
159
- case 'utf8':
160
- case 'utf-8':
161
- let utf8String = '';
162
- for (let i = 0; i < input.length; i++) {
163
- let code;
164
- if (input[i] < 0x80) {
165
- code = input[i];
166
- }
167
- else if (input[i] < 0xe0) {
168
- code = ((input[i] & 0x1f) << 6) | (input[++i] & 0x3f);
169
- }
170
- else if (input[i] < 0xf0) {
171
- code = ((input[i] & 0x0f) << 12) | ((input[++i] & 0x3f) << 6) | (input[++i] & 0x3f);
172
- }
173
- else {
174
- code = ((input[i] & 0x07) << 18) | ((input[++i] & 0x3f) << 12) | ((input[++i] & 0x3f) << 6) | (input[++i] & 0x3f);
175
- }
176
- utf8String += String.fromCharCode(code);
177
- }
178
- return utf8String;
179
- case 'utf16le':
180
- case 'ucs2':
181
- case 'ucs-2':
182
- let utf16leString = '';
183
- for (let i = 0; i < input.length; i += 2) {
184
- const code = input[i] | (input[i + 1] << 8);
185
- utf16leString += String.fromCharCode(code);
186
- }
187
- return utf16leString;
188
- case 'base64':
189
- return btoa(decode(input, 'utf-8'));
190
- case 'base64url':
191
- return decode(input, 'base64').replace('/', '_').replace('+', '-');
192
- case 'hex':
193
- return Array.from(input)
194
- .map(e => e.toString(16).padStart(2, '0'))
195
- .join('');
196
- default:
197
- throw new ApiError(ErrorCode.EINVAL, 'Invalid encoding: ' + encoding);
198
- }
114
+ return Array.from(input)
115
+ .map(char => String.fromCharCode(char))
116
+ .join('');
199
117
  }
200
118
  /**
201
119
  * Decodes a directory listing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "A filesystem in your browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -51,8 +51,9 @@
51
51
  "prepublishOnly": "npm run build"
52
52
  },
53
53
  "dependencies": {
54
- "@types/node": "^14.0.0",
54
+ "@types/node": "^20.12.5",
55
55
  "@types/readable-stream": "^4.0.10",
56
+ "buffer": "^6.0.3",
56
57
  "minimatch": "^9.0.3",
57
58
  "readable-stream": "^4.5.2"
58
59
  },