Skip to content

Commit

Permalink
feat: added openAsBlob polyfill
Browse files Browse the repository at this point in the history
still wip
  • Loading branch information
eddienubes committed Feb 10, 2024
1 parent 979d5e7 commit 2daecb7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@vitest/coverage-v8": "^1.2.2",
"compare-versions": "^6.1.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CookieSameSiteProperty,
SetCookieHeaderProperties
} from './types.js';
import { Blob } from 'node:buffer';

export const serializeToString = (value: unknown): string => {
const result = JSON.stringify(value);
Expand Down Expand Up @@ -48,7 +49,6 @@ export const isBinary = (value: unknown): boolean => {
return (
value instanceof ArrayBuffer ||
value instanceof Blob ||
value instanceof File ||
value instanceof Buffer
);
};
Expand Down
19 changes: 19 additions & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
import '../src/polyfill.js';
import fs from 'node:fs';
import { Readable } from 'node:stream';

Check warning on line 3 in test/setup.ts

View workflow job for this annotation

GitHub Actions / CI (16.x)

'Readable' is defined but never used

Check warning on line 3 in test/setup.ts

View workflow job for this annotation

GitHub Actions / CI (18.x)

'Readable' is defined but never used

Check warning on line 3 in test/setup.ts

View workflow job for this annotation

GitHub Actions / CI (20.x)

'Readable' is defined but never used
import { compare } from 'compare-versions';
import { Blob } from 'node:buffer';

const version = process.version;

// https://nodejs.org/api/fs.html#fsopenasblobpath-options
if (!compare(version.replace('v', ''), '19.8.0', '>')) {
// @ts-expect-error

Check warning on line 11 in test/setup.ts

View workflow job for this annotation

GitHub Actions / CI (16.x)

Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer

Check warning on line 11 in test/setup.ts

View workflow job for this annotation

GitHub Actions / CI (18.x)

Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer

Check warning on line 11 in test/setup.ts

View workflow job for this annotation

GitHub Actions / CI (20.x)

Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer
fs.openAsBlob = async (filePath: string): Blob => {
const readable = fs.createReadStream(filePath);

const stream = await readable.toArray();
const blob = new Blob(stream);

return blob;
};
}

0 comments on commit 2daecb7

Please sign in to comment.