Bug - Fixed JavaScript: bufferToFile() fails due to type issues (+ patch added)

philmasterplus

Active member
The bufferToFile(string, string) function is the JS-equivalent of the ASH function buffer_to_file(string, string). However, calling this function in JS currently fails with:

Code:
> js require("kolmafia").bufferToFile("asdf", "foo.txt");

Script exception: Function 'buffer_to_file( string, string )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (command line#1)

I suspect this is because the "compatibility layer" between ASH and JS does not translate string type to buffer for this call. Unfortunately, there is no native "Buffer" type in our JS runtime, so we can't use this function at all.
 
Last edited:

MCroft

Developer
Staff member
Is this fileToBuffer or bufferToFile? you mention both below.
The fileToBuffer(string, string) function is the JS-equivalent of the ASH function file_to_buffer(string, string). However, calling this function in JS currently fails with:

Code:
> js require("kolmafia").bufferToFile("asdf", "foo.txt");

Code:
> ashref buffer

boolean buffer_to_file( buffer, string )
buffer file_to_buffer( string )

> jsref buffer

boolean bufferToFile(string, string)
string fileToBuffer(string)

> js require("kolmafia").fileToBuffer("foo.txt");

Returned:
 
Last edited:

philmasterplus

Active member
Here's a patch that special-cases bufferToFile() so that, if the first argument is a String, it is converted to a buffer (Java StringBuffer) before being passed to the actual function. It does not affect the ASH runtime in any way.
 

Attachments

  • philmasterplus-js-buffer-to-file-fix.patch
    1.3 KB · Views: 2

gausie

D̰͕̝͚̤̥̙̐̇̑͗̒e͍͔͎͈͔ͥ̉̔̅́̈l̠̪̜͓̲ͧ̍̈́͛v̻̾ͤe͗̃ͥ̐̊ͬp̔͒ͪ
Staff member
Thanks for this phil! r20629
 
Top