Skip to content

Instantly share code, notes, and snippets.

@neckaros
neckaros / FileInput.svelte
Created March 18, 2022 10:34
Simple File input for Svelte. The css classes use Tailwind but fill free to replace
<script lang="ts">
import { nanoid } from "nanoid";
export let disabled: boolean = false;
export let title: string = 'CHOOSE FILES'
export let variant: 'confirm' | 'cancel' | 'normal' = "normal";
export let id: string = nanoid(); // or any other way to generate a unique id like Math.random().toString()
export const multiple: boolean = false;
</script>
@neckaros
neckaros / CryptoTransformStream.test.ts
Last active July 30, 2022 14:38
Create a crypto.subtle transform stream to transform AES-CBC encoded stream to decrypted data stream. Require a browser that implement pipeThough: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeThrough#Browser_compatibility
import { Readable } from "stream";
import { CryptoAesCBC } from "./crypt";
import { AesDecryptStream, AesEncryptStream } from "./cryptostream";
import { ReadableStream, WritableStream } from "stream/web";
describe("Decrypt", () => {
it("shoud decrypt file below 16 bits", async () => {
const buf = Buffer.alloc(12); // Creating a new Buffer
buf.write("Hello world!");
const crypto = new CryptoAesCBC('testkey');