-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from velascoandres/feat/whiteboard-gzip
Feat/whiteboard gzip
- Loading branch information
Showing
12 changed files
with
250 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const b64encode = (arrayBuffer: ArrayBuffer) => { | ||
const buffer = Buffer.from(arrayBuffer) | ||
const base64String = buffer.toString('base64') | ||
|
||
return base64String | ||
} | ||
|
||
export const b64decode = (base64: string) => { | ||
const buffer = Buffer.from(base64, 'base64') | ||
|
||
return new Uint8Array(buffer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { b64encode } from './base64' | ||
import { | ||
b64toStream, | ||
compressStream, | ||
decompressStream, | ||
JSONtoStream, | ||
responseToBuffer | ||
} from './compress' | ||
|
||
export const compressContent = async (content: Record<string, unknown>) => { | ||
const compressedStream = await compressStream(JSONtoStream(content)) | ||
const compressedBuffer = await responseToBuffer(compressedStream) | ||
|
||
return b64encode(compressedBuffer) | ||
} | ||
|
||
export const decompressContent = (base64: string): Promise<Record<string, unknown>> => { | ||
const contentResponse = decompressStream(b64toStream(base64)) | ||
|
||
return contentResponse.json() as Promise<Record<string, unknown>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { b64decode,b64encode } from './base64' | ||
|
||
export const JSONtoStream = (data: object) => { | ||
return new Blob([JSON.stringify(data)], { | ||
type: 'text/plain' | ||
}).stream() | ||
} | ||
|
||
export const b64toStream = (b64: string) => { | ||
return new Blob([b64decode(b64)], { | ||
type: 'text/plain' | ||
}).stream() | ||
} | ||
|
||
export const responseToJSON = async (response: Response): Promise<Record<string, unknown>> => { | ||
const blob = await response.blob() | ||
|
||
const textResponse = await blob.text() | ||
|
||
return JSON.parse(textResponse) as Record<string, unknown> | ||
} | ||
|
||
export const responseToB64 = async (response: Response) => { | ||
const blob = await response.blob() | ||
const buffer = await blob.arrayBuffer() | ||
|
||
return b64encode(buffer) | ||
} | ||
|
||
export const responseToBuffer = async (response: Response) => { | ||
const blob = await response.blob() | ||
|
||
return blob.arrayBuffer() | ||
} | ||
|
||
export const compressStream = async (stream: ReadableStream<Uint8Array>) => { | ||
const compressedReadableStream = stream.pipeThrough( | ||
new CompressionStream('gzip') | ||
) | ||
|
||
return new Response(compressedReadableStream) | ||
} | ||
|
||
export const decompressStream = (stream: ReadableStream<Uint8Array>) => { | ||
const compressedReadableStream = stream.pipeThrough( | ||
new DecompressionStream('gzip') | ||
) | ||
|
||
return new Response(compressedReadableStream) | ||
} |
42 changes: 0 additions & 42 deletions
42
src/server/api/whiteboard/usecases/find-public-whiteboard.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.