Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better web support #68

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@starfiles/hydrafiles",
"version": "0.3.3",
"version": "0.3.4",
"description": "The headless storage network.",
"main": "src/hydrafiles.ts",
"exports": {
Expand Down
9 changes: 5 additions & 4 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function getFileHandle(directoryHandle: DirectoryHandle, path: string, tou

for (let i = 0; i < parts.length; i++) {
const part = parts[i];
console.log("zzzz", parts, i, part);

if (i === parts.length - 1) return await currentHandle.getFileHandle(part, { create: touch });
else currentHandle = await currentHandle.getDirectoryHandle(part, { create: true });
Expand All @@ -43,14 +42,15 @@ class FS {
};

mkdir = async (path: string) => {
if (await this.exists(path)) return;
console.log(`mkdir ${path}`);
if (await this.exists(path)) return;
if (!this.init) throw new Error("FS not initialized");
if (this.directoryHandle !== undefined) await this.directoryHandle.getDirectoryHandle(path, { create: true });
else await Deno.mkdir(path);
};

readDir = async (path: string): Promise<string[]> => {
console.log(`readdir ${path}`);
if (!this.init) throw new Error("FS not initialized");
const entries: string[] = [];

Expand Down Expand Up @@ -121,11 +121,12 @@ class FS {
};

getFileSize = async (path: string): Promise<number> => {
console.log(`${path} Getting file size`);
if (!this.init) throw new Error("FS not initialized");

if (this.directoryHandle !== undefined) {
try {
const fileHandle = await this.directoryHandle.getFileHandle(path);
const fileHandle = await getFileHandle(this.directoryHandle, path);
const file = await fileHandle.getFile();
return file.size; // Return file size in bytes
} catch (e) {
Expand All @@ -146,7 +147,7 @@ class FS {

if (this.directoryHandle !== undefined) {
try {
const fileHandle = await this.directoryHandle.getFileHandle(path);
const fileHandle = await getFileHandle(this.directoryHandle, path);
await fileHandle.remove(); // Remove the file
} catch (e) {
const error = e as Error;
Expand Down