Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Commit

Permalink
Fix: fs.readFileSync returns Buffer instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzmich committed Apr 8, 2019
1 parent 7889ac5 commit a864a50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/kotlin/node/node.kt
Expand Up @@ -30,11 +30,18 @@ external object process {
val argv0: String
}

external interface Buffer {
// Using different name instead so it won't collide with `Any::toString`
// `Any::toString` consider Buffers "arrayish" and returns "[...]"
@JsName("toString")
fun decodeToString(): String
}

@JsModule("fs")
external object fs {
fun argv(index: Int): String
fun writeFileSync(path: String, text: String): Unit
fun readFileSync(path: String): String
fun readFileSync(path: String): Buffer
fun readFileSync(path: String, encodingOptions: EncodingOptions): String
fun readdirSync(path: String): Array<String>
fun existsSync(path: String): Boolean
Expand All @@ -48,4 +55,4 @@ external object module {
class EncodingOptions(val encoding: String = "utf8")

external val __dirname: String
external val __filename: String
external val __filename: String
2 changes: 1 addition & 1 deletion src/main/kotlin/ts2kt/translate.kt
Expand Up @@ -41,7 +41,7 @@ private fun getScriptSnapshotFromFile(path: String): IScriptSnapshot {
var scriptSnapshot = file2scriptSnapshotCache[path]

if (scriptSnapshot == null) {
scriptSnapshot = fromString(fs.readFileSync(path).toString())
scriptSnapshot = fromString(fs.readFileSync(path).decodeToString())
file2scriptSnapshotCache[path] = scriptSnapshot
}

Expand Down

0 comments on commit a864a50

Please sign in to comment.