vsazel
07/30/2019, 10:38 AMfun createRandomFile(path: String, size: Long) {
val fd = openSync(path, "a+")
ftruncateSync(fd, size)
closeSync(fd)
}
ftruncateSync is Node.js function defined in Kotlin as:
external fun ftruncateSync(fd: Number, len: Number? = definedExternally /* null */): Unit = definedExternally
I can pass Int to ftruncateSync with no problems, but top size is 1GiB for the file, because size of Int is limited.
When I use Long, it ends with The "len" argument must be of type number. Received type object. So obviously there is no conversion for Long. Can this be done somehow?Robert Jaros
07/30/2019, 10:50 AMNumber instead of Longvsazel
07/30/2019, 10:57 AMcreateRandomFile size argument to Number
createRandomFile("/tmp/something", 5L*1024L*1024L*1024L)Robert Jaros
07/30/2019, 11:05 AM(5L*1024L*1024L*1024L).toFloat()vsazel
07/30/2019, 11:34 AMSvyatoslav Kuzmich [JB]
07/30/2019, 11:35 AMtoDouble() would be a bit more future-proof and consistent with other backendsZachary Grafton
07/30/2019, 12:14 PMtoDouble function works in this case due to the underlying representation of Javascript numbers always being a double value. The kotlin Long datatype is actually an object with a couple of properties, and it's not quite what you would expect when working with a primitive type.Svyatoslav Kuzmich [JB]
07/30/2019, 12:17 PMThere's no 64 bit integer number in JavaScript, so kotlin.Long is not mapped to any JavaScript object, it's emulated by a Kotlin class.
Zachary Grafton
07/30/2019, 12:23 PM