-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bd932b
commit 905a4a1
Showing
5 changed files
with
102 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CHANGELOG | ||
|
||
## 2024-07-19 | ||
|
||
- Better sharing support. When clicking "File -> Share", the Data Contract creates a shareable URL with the Data Contract YAML encoded in the URL. Previously, we only used base64 encoding, but it turned out that may lead to some URLs that are too long. To solve this, we gzip before encoding with base64. This allows for much large data contracts to be shared. |
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,82 @@ | ||
/* encoded = encodebase64(gzip(yaml)) */ | ||
export async function encodeYamlCode(yamlCode) { | ||
const compressed = await gzip(yamlCode); | ||
return window.btoa(String.fromCharCode(...new Uint8Array(compressed))); | ||
} | ||
|
||
/* decoded = gunzip(decodebase64(queryparameter)) */ | ||
export async function decodeQueryParameter(queryParameter) { | ||
const compressed = Uint8Array.from(window.atob(queryParameter), c => c.charCodeAt(0)); | ||
const decompressed = await gunzip(compressed); | ||
const decoder = new TextDecoder(); | ||
return decoder.decode(decompressed) | ||
} | ||
|
||
async function gzip(input) { | ||
const encoder = new TextEncoder(); | ||
const data = encoder.encode(input); | ||
|
||
const stream = new CompressionStream('gzip'); | ||
const writer = stream.writable.getWriter(); | ||
writer.write(data); | ||
writer.close(); | ||
|
||
const compressedStream = stream.readable; | ||
const reader = compressedStream.getReader(); | ||
|
||
let chunks = []; | ||
let done = false; | ||
|
||
while (!done) { | ||
const { value, done: doneReading } = await reader.read(); | ||
if (value) { | ||
chunks.push(value); | ||
} | ||
done = doneReading; | ||
} | ||
|
||
let size = 0; | ||
chunks.forEach(chunk => size += chunk.length); | ||
|
||
let compressed = new Uint8Array(size); | ||
let offset = 0; | ||
chunks.forEach(chunk => { | ||
compressed.set(chunk, offset); | ||
offset += chunk.length; | ||
}); | ||
|
||
return compressed; | ||
} | ||
|
||
async function gunzip(data) { | ||
const stream = new DecompressionStream('gzip'); | ||
const writer = stream.writable.getWriter(); | ||
writer.write(data); | ||
writer.close(); | ||
|
||
const decompressedStream = stream.readable; | ||
const reader = decompressedStream.getReader(); | ||
|
||
let chunks = []; | ||
let done = false; | ||
|
||
while (!done) { | ||
const { value, done: doneReading } = await reader.read(); | ||
if (value) { | ||
chunks.push(value); | ||
} | ||
done = doneReading; | ||
} | ||
|
||
let size = 0; | ||
chunks.forEach(chunk => size += chunk.length); | ||
|
||
let decompressed = new Uint8Array(size); | ||
let offset = 0; | ||
chunks.forEach(chunk => { | ||
decompressed.set(chunk, offset); | ||
offset += chunk.length; | ||
}); | ||
|
||
return decompressed; | ||
} |
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