Skip to content
Open
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
4 changes: 4 additions & 0 deletions filekit-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ kotlin {
implementation(libs.kotlinx.browser)
}

webMain.dependencies {
implementation(libs.kotlinx.browser)
}

jvmMain.dependencies {
implementation(libs.jna.platform)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,46 @@ public expect suspend fun PlatformFile.readString(): String
*/
public expect fun PlatformFile.mimeType(): MimeType?

/**
* Returns the path string of this file.
*/
public expect val PlatformFile.path: String

/**
* Returns the parent of this file, or null if it does not have a parent.
*
* @return The parent [PlatformFile], or null.
*/
public expect fun PlatformFile.parent(): PlatformFile?

/**
* Checks if this file is a regular file.
*
* @return `true` if it is a regular file, `false` otherwise.
*/
public expect fun PlatformFile.isRegularFile(): Boolean

/**
* Checks if this file is a directory.
*
* @return `true` if it is a directory, `false` otherwise.
*/
public expect fun PlatformFile.isDirectory(): Boolean

/**
* Lists the files in this directory and passes them to the given block.
*
* @param block A callback function that receives a list of [PlatformFile]s.
*/
public expect inline fun PlatformFile.list(block: (List<PlatformFile>) -> Unit)

/**
* Lists the files in this directory.
*
* @return A list of [PlatformFile]s in this directory.
*/
public expect fun PlatformFile.list(): List<PlatformFile>

/**
* Starts accessing a security-scoped resource.
*
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ public expect fun PlatformFile(base: PlatformFile, child: String): PlatformFile
*/
public expect fun PlatformFile.toKotlinxIoPath(): Path

/**
* Returns the path string of this file.
*/
public expect val PlatformFile.path: String

/**
* Returns the parent of this file, or null if it does not have a parent.
*
* @return The parent [PlatformFile], or null.
*/
public expect fun PlatformFile.parent(): PlatformFile?

/**
* Returns the absolute path string of this file.
*
Expand Down Expand Up @@ -89,20 +77,6 @@ public expect fun PlatformFile.source(): RawSource
*/
public expect fun PlatformFile.sink(append: Boolean = false): RawSink

/**
* Checks if this file is a regular file.
*
* @return `true` if it is a regular file, `false` otherwise.
*/
public expect fun PlatformFile.isRegularFile(): Boolean

/**
* Checks if this file is a directory.
*
* @return `true` if it is a directory, `false` otherwise.
*/
public expect fun PlatformFile.isDirectory(): Boolean

/**
* Checks if this file path is absolute.
*
Expand Down Expand Up @@ -233,20 +207,6 @@ internal expect suspend fun PlatformFile.prepareDestinationForWrite(source: Plat
public fun PlatformFile.createDirectories(mustCreate: Boolean = false): Unit =
SystemFileSystem.createDirectories(toKotlinxIoPath(), mustCreate)

/**
* Lists the files in this directory and passes them to the given block.
*
* @param block A callback function that receives a list of [PlatformFile]s.
*/
public expect inline fun PlatformFile.list(block: (List<PlatformFile>) -> Unit)

/**
* Lists the files in this directory.
*
* @return A list of [PlatformFile]s in this directory.
*/
public expect fun PlatformFile.list(): List<PlatformFile>

/**
* Atomically moves this file to the destination.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.vinceglb.filekit

import kotlin.js.ExperimentalWasmJsInterop
import kotlin.js.toDouble
import kotlin.time.Instant

/**
* Implementation of WebFileHandle
* Using just the W3C File object
*/
@OptIn(ExperimentalWasmJsInterop::class)
public class FileHandleFile(
public val file: FileExt,
public val parent: WebFileHandle? = null,
) : WebFileHandle {
override val name: String
get() = file.name
override val type: String
get() = file.type
override val size: Long
get() = file.size.toDouble().toLong()
override val path: String
get() = file.webkitRelativePath ?: ""
public override val isDirectory: Boolean = false
public override val isRegularFile: Boolean = true
override val lastModified: Instant
get() = Instant.fromEpochMilliseconds(file.lastModified.toDouble().toLong())

override fun getFile(): FileExt = file

override fun getParent(): WebFileHandle? =
parent

override fun list(): List<WebFileHandle> =
emptyList()
}

public fun PlatformFile(file: FileExt): PlatformFile = PlatformFile(fh = FileHandleFile(file))
Loading