Skip to content

Commit

Permalink
Style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jan 15, 2025
1 parent 7fb2ea4 commit d5e2d47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
60 changes: 30 additions & 30 deletions packages/form-data-parser/src/lib/form-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,41 +88,41 @@ export async function parseFormData(
uploadHandler: FileUploadHandler = defaultFileUploadHandler,
parserOptions?: MultipartParserOptions,
): Promise<FormData> {
if (isMultipartRequest(request)) {
let formData = new FormData();
let promises: Promise<void | null | string | File>[] = [];

for await (let part of parseMultipartRequest(request, parserOptions)) {
if (!part.name) continue;

if (part.isFile) {
let value = uploadHandler(new FileUpload(part));

if (value != null) {
if (isPromise(value)) {
let fieldName = part.name;
promises.push(
value.then((file) => {
if (file != null) {
formData.append(fieldName, file);
}
}),
);
} else {
formData.append(part.name, value);
}
if (!isMultipartRequest(request)) {
return request.formData();
}

let formData = new FormData();
let promises: Promise<void | null | string | File>[] = [];

for await (let part of parseMultipartRequest(request, parserOptions)) {
if (!part.name) continue;

if (part.isFile) {
let value = uploadHandler(new FileUpload(part));

if (value != null) {
if (isPromise(value)) {
let fieldName = part.name;
promises.push(
value.then((file) => {
if (file != null) {
formData.append(fieldName, file);
}
}),
);
} else {
formData.append(part.name, value);
}
} else {
formData.append(part.name, await part.text());
}
} else {
formData.append(part.name, await part.text());
}

await Promise.all(promises);

return formData;
}

return request.formData();
await Promise.all(promises);

return formData;
}

function isPromise<T>(obj: unknown): obj is Promise<T> {
Expand Down
16 changes: 8 additions & 8 deletions packages/tar-parser/src/lib/tar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ async function bufferBytes(stream: ReadableStream<Uint8Array>): Promise<Uint8Arr
return result;
}

async function computeHash(buffer: Uint8Array, algorithm = 'SHA-256'): Promise<string> {
let digest = await crypto.subtle.digest(algorithm, buffer);
return Array.from(new Uint8Array(digest))
.map((byte) => byte.toString(16).padStart(2, '0'))
.join('')
.slice(0, 8);
}

async function bufferString(
stream: ReadableStream<Uint8Array>,
encoding = 'utf-8',
Expand All @@ -49,6 +41,14 @@ async function bufferString(
return string;
}

async function computeHash(buffer: Uint8Array, algorithm = 'SHA-256'): Promise<string> {
let digest = await crypto.subtle.digest(algorithm, buffer);
return Array.from(new Uint8Array(digest))
.map((byte) => byte.toString(16).padStart(2, '0'))
.join('')
.slice(0, 8);
}

describe('TarParser', () => {
it('parses express-4.21.1.tgz', async () => {
let entries: Record<string, string> = {};
Expand Down

0 comments on commit d5e2d47

Please sign in to comment.