Readfile command to read binary file error!

Things you’d like to miss in the future...
Post Reply
youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Readfile command to read binary file error!

Post by youtao6256 »

I would like to use readfile (, "b", 20, 25) command to read the wav file 25,26 bytes of hexadecimal data, but found that the command read the hexadecimal data and source files of the ten Hexadecimal data is not the same? The source file data is 0xAC44, but the incoming data bits 0x3F44, using the pattern “b” or “t” are not correct.

Source file hexadecimal,the wav file 25,26 bytes of hexadecimal data is 0xAC44
02.jpg
02.jpg (523.25 KiB) Viewed 1027 times

script:text hexdump (readfile(, "b",20, ,25),,"b"),1,);
03.jpg
03.jpg (397.94 KiB) Viewed 1027 times

The result of the readfile command. 25,26 bytes of hexadecimal data is 0x3F44
04.jpg
04.jpg (438.69 KiB) Viewed 1027 times

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Readfile command to read binary file error!

Post by highend »

Don't know where this is coming from, but on my system (german locale), it displays the correct result:
binary.png
binary.png (7.02 KiB) Viewed 1024 times
One of my scripts helped you out? Please donate via Paypal

youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Re: Readfile command to read binary file error!

Post by youtao6256 »

my system is win7,64 bit
01.jpg
01.jpg (104.95 KiB) Viewed 1023 times

admin
Site Admin
Posts: 60597
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Readfile command to read binary file error!

Post by admin »

1) Do you see the correct values when you view the file with command File | Quick File View (Ctrl+Q)?

2) What is your locale? Please show this section from Help | Various Information:

Code: Select all

System Locale ID: 1031 (de-DE)
Thread Locale ID: 1031 (de-DE)
Default ANSI Code Page: 1252  (ANSI - Lateinisch I)
Active ANSI Code Page: 1252  (ANSI - Lateinisch I)
Default OEM code page: 850   (OEM - Multilingual Lateinisch I)
Active OEM Code Page: 850   (OEM - Multilingual Lateinisch I)
Is DBCS Code Page: No

youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Re: Readfile command to read binary file error!

Post by youtao6256 »

I know that this bug related to the system area, when the system format is set to Chinese, read the data wrong, set the format for the United States is correct, I am a Chinese user, hoping to solve this problem.
05.jpg
05.jpg (432 KiB) Viewed 1008 times

youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Re: Readfile command to read binary file error!

Post by youtao6256 »

I am in China, the language environment is windows7 64bit Chinese operating system, windows10 the same as the problem.

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Readfile command to read binary file error!

Post by highend »

Please look at this post (viewtopic.php?p=151761#p151761)
and provide the necessary information
One of my scripts helped you out? Please donate via Paypal

youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Re: Readfile command to read binary file error!

Post by youtao6256 »

System Locale ID: 2052 (zh-CN)
Thread Locale ID: 2052 (zh-CN)
Default ANSI Code Page: 936 (ANSI/OEM - 简体中文 GBK)
Active ANSI Code Page: 936 (ANSI/OEM - 简体中文 GBK)
Default OEM code page: 936 (ANSI/OEM - 简体中文 GBK)
Active OEM Code Page: 936 (ANSI/OEM - 简体中文 GBK)
Is DBCS Code Page: Yes

Quick File View (Ctrl+Q)
06.jpg
06.jpg (482.74 KiB) Viewed 1001 times

admin
Site Admin
Posts: 60597
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Readfile command to read binary file error!

Post by admin »

Thanks. Fix comes with next beta version.

youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Re: Readfile command to read binary file error!

Post by youtao6256 »

Hi, I have been updated to 18.20.0300 But how does the readfile command read errors?

script:text hexdump (readfile(, "b",50, ,1),,"b"),1,);
002.JPG
002.JPG (170.64 KiB) Viewed 940 times
Look at the location of 18h, 0xAC44 or become 0x3F44
001.JPG
001.JPG (163.17 KiB) Viewed 940 times
Quick View Information (ctrl + Q)
003.JPG
003.JPG (310.89 KiB) Viewed 940 times
004.JPG
004.JPG (180.67 KiB) Viewed 940 times
Wav file
voice00110k16bit.rar
(321.21 KiB) Downloaded 42 times

admin
Site Admin
Posts: 60597
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Readfile command to read binary file error!

Post by admin »

You should use the new "r" mode (r = raw bytes, binary safe, no conversion):

Code: Select all

text hexdump(readfile( , "r", 50), , "b");  //you see the true bytes

youtao6256
Posts: 20
Joined: 21 Aug 2017 06:45

Re: Readfile command to read binary file error!

Post by youtao6256 »

Thank you very much for your help, this is indeed the case, I hope you can update the script command help, there are only "t" and "b" mode.
001.JPG
001.JPG (81.82 KiB) Viewed 915 times
But I used the writefile command encountered problems, trouble to help me see where I use the wrong!

script:writefile("test-out.txt", readfile(, "r"),,"r");
File size and data are problematic!
002.JPG
002.JPG (95.98 KiB) Viewed 915 times
003.JPG
003.JPG (125.21 KiB) Viewed 915 times
script:writefile("test-out.txt", readfile(, "r"),,"b");
File size and data are problematic!
004.JPG
004.JPG (136.89 KiB) Viewed 915 times
005.JPG
005.JPG (163.87 KiB) Viewed 915 times

admin
Site Admin
Posts: 60597
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Readfile command to read binary file error!

Post by admin »

You are right, the fix was not complete. Next version should have it all. Then you can do either of these:

Code: Select all

writefile("test-out.txt", readfile(, "r"), , "r");

Code: Select all

writefile("test-out.txt", readfile(, "ru"), , "ru");
The help file us updated with each bigger release.

Post Reply