XTLS/libXray

use string based, instead of file

Opened this issue · 3 comments

This library is great. But to run it on Android, it should be optimized.

For example, when we want to use commands like share.go, the strings must be written in the file each time, and then specify the path of the file to this command for output.

This causes more pressure. Because to use any command, we have to write it in the file and give the file path to the program.

For example, consider this command:

val decode = "
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw..."

val array = decode.split("\n").toTypedArray()

for (strings in array) {
 
 // first write each strings to a file
 writeFile(path, strings) 

 // then give path of file to lib
 LibXray.convertShareTextToXrayJson(path, outputPath)

 // then read outputPath and ping them
 LibXray.Ping(datDir, outputPath,  timeout, url, proxy)
}

each step should written in disk and then read it from there.

But if it is as follows, all the steps are in string and it makes it more efficient and reduces the pressure on the disk;

val decode = "
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw...\n
vless://dqwdqw..."

val array = decode.split("\n").toTypedArray()

for (strings in array) {
 
 // the final output in string
 val share = LibXray.convertShareTextToXrayJson(path, strings)

 // read output in string format
 LibXray.Ping(datDir, share, timeout, url, proxy)
}

please look at this sub, it has about +100 configs and by this way all of them should be write in disk every time. it will cool if this lib give us all of outputs in the string format.
my knowledge is not enough in go, but i just checked AndroidLibXrayLite and And I saw this line. i dont know how strings.NewReader works in go. But if anyone can please help to improve this library.

There is no need to do this. convertShareTextToXrayJson supports the whole sub file (base64 encoded text, plain text, even original config json), and then you will get multiple outbounds in one json file.
But yes, the implemention of AndroidLibXrayLite is better. I will consider to improve this api.

@yiguous oh i didn't knew that. but it need a directory to return output in json. anyway its not print data as string in android side.

also what about other functions?

it will better if all of functions get their arguments by string. also return outputs in string. i tested this library functions and all of them is file based.

the putting functions args in strings and return their data in string format is more clean. so whatever we can write their string outputs to the file or do anything with the returned data in android side if needed.

i don't know too much about go, but if the creating file is possible in GO, so each functions can get the strings and save them to the file in GO lang way. i mean something like temporary file and read them from there and after that clean that temp file.

or it will more better if can parse strings directly for each functions with their jobs.

thanks.

Hello, I have restructured libXray. All apis have been changed to string-based except Run/Ping/Test, which need Xray core loaded.