Skip to content

Commit

Permalink
Support larger file downloads for in browser data science
Browse files Browse the repository at this point in the history
  • Loading branch information
breck7 committed Jan 6, 2025
1 parent 8ad3018 commit 96506b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll-cli",
"version": "165.0.0",
"version": "165.1.0",
"description": "A language for scientists of all ages. A curated collection of tools for refining and sharing thoughts.",
"main": "scroll.js",
"engines": {
Expand Down
19 changes: 15 additions & 4 deletions parsers/root.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ scrollParser
return hakonParser
}
readSyncFromFileOrUrl(fileOrUrl) {
if (!this.isNodeJs()) return localStorage.getItem(fileOrUrl) || ""
if (!this.isNodeJs()) return this.getInBrowser(fileOrUrl)
const isUrl = fileOrUrl.match(/^https?\:[^ ]+$/)
if (!isUrl) return this.root.readFile(fileOrUrl)
return this.readFile(this.makeFullPath(new URL(fileOrUrl).pathname.split('/').pop()))
}
getInBrowser(key) {
return localStorage.getItem(key) || (window.inMemStorage ? window.inMemStorage[key] : "") || ""
}
async fetch(url, filename) {
const isUrl = url.match(/^https?\:[^ ]+$/)
if (!isUrl) return
Expand Down Expand Up @@ -199,7 +202,7 @@ scrollParser
if (this.logger) this.logger.log(message)
}
async fetchBrowser(url) {
const content = localStorage.getItem(url)
const content = this.getInBrowser(url)
if (content) return content
return this.downloadToLocalStorage(url)
}
Expand All @@ -213,8 +216,16 @@ scrollParser
async downloadToLocalStorage(url) {
const response = await fetch(url)
const blob = await response.blob()
localStorage.setItem(url, await blob.text())
return localStorage.getItem(url)
const text = await blob.text()
try {
localStorage.setItem(url, text)
return localStorage.getItem(url)
} catch (err) {
if (!window.inMemStorage) window.inMemStorage = {}
window.inMemStorage[url] = text
console.error(err)
return text
}
}
readFile(filename) {
const {path} = this
Expand Down
3 changes: 3 additions & 0 deletions releaseNotes.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ciBadges.scroll
br
thinColumns

📦 165.1.0 1/06/2025
🎉 support larger data science sessions by using memory if not enough local storage

📦 165.0.0 1/05/2025
🎉 quick css and js tags now compile to blank html snippets
⚠️ BREAKING: (no one should be affected) CSS and Javascript tags will no longer be included by default when compiling snippets
Expand Down

0 comments on commit 96506b3

Please sign in to comment.