-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For dynamic mode, even if the rdoc is gzipped, parsing it can result in a big performance hit. For example if a user load a 1MB gzipped archive, which then decompresses into a >70MB JSON object, this can result in slower parsing. We need to think about how to streamline large rdocs. This commit adds a restriction on the number of matches to show in dynamic mode (maxMatches = 1)
- Loading branch information
Showing
7 changed files
with
203 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
import pako from 'pako' | ||
|
||
/** | ||
* Checks if the given file is gzipped | ||
* @param {File} file - The file to check | ||
* @returns {Promise<boolean>} - True if the file is gzipped, false otherwise | ||
*/ | ||
export const isGzipped = async (file) => { | ||
const arrayBuffer = await file.arrayBuffer() | ||
const uint8Array = new Uint8Array(arrayBuffer) | ||
return uint8Array[0] === 0x1f && uint8Array[1] === 0x8b | ||
} | ||
|
||
/** | ||
* Decompresses a gzipped file | ||
* @param {File} file - The gzipped file to decompress | ||
* @returns {Promise<string>} - The decompressed file content as a string | ||
*/ | ||
export const decompressGzip = async (file) => { | ||
const arrayBuffer = await file.arrayBuffer() | ||
const uint8Array = new Uint8Array(arrayBuffer) | ||
const decompressed = pako.inflate(uint8Array, { to: 'string' }) | ||
return decompressed | ||
} | ||
|
||
/** | ||
* Reads a file as text | ||
* @param {File} file - The file to read | ||
* @returns {Promise<string>} - The file content as a string | ||
*/ | ||
export const readFileAsText = (file) => { | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader() | ||
reader.onload = (event) => resolve(event.target.result) | ||
reader.onerror = (error) => reject(error) | ||
reader.readAsText(file) | ||
}) | ||
} |
Oops, something went wrong.