![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Convert Byte() to string I have a function to read a binary file. I now need to convert the binary to a string. Does someone by chance have a function that does this? If so could you please post it, or show me an alternate method, or show me how I can tweak my code so far (see below) to return a string from the original binary? Function GetBinaryFileStream(argFullName) Const adTypeBinary = 1 Dim oBinaryStream Set oBinaryStream = CreateObject("ADODB.Stream") oBinaryStream.Type = adTypeBinary oBinaryStream.Open oBinaryStream.LoadFromFile argFullName GetBinaryFileStream = oBinaryStream.Read End Function Thanks much in advance. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Convert Byte() to string I have a class I wrote that uses Textstream and provides full binary file functionality - reading, writing, returning numeric values represented by a series of bytes... the basic things that one would want to do with a binary file. www.jsware.net/jsware/scripts.php5#bints Textstream can do it all. You just have to be careful of how you handle data that might contain nulls. A string, a stream and an array are not really different things, so I don't know what you mean by converting a binary file to string. Textstream will read it out as a string, and that string can be handled, or written to a new file, but you can't "look at it too closely" unless you convert the nulls. Quote: > I have a function to read a binary file. I now need to convert the binary Quote: > a string. Does someone by chance have a function that does this? If so Quote: > you please post it, or show me an alternate method, or show me how I can > tweak my code so far (see below) to return a string from the original Quote: > > Function GetBinaryFileStream(argFullName) > Const adTypeBinary = 1 > Dim oBinaryStream > Set oBinaryStream = CreateObject("ADODB.Stream") > oBinaryStream.Type = adTypeBinary > oBinaryStream.Open > oBinaryStream.LoadFromFile argFullName > GetBinaryFileStream = oBinaryStream.Read > End Function > > Thanks much in advance. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Convert Byte() to string "XP" <XP@xxxxxx> wrote in message news:9747CDDE-1451-40BD-AE0A-D5E70F3A52B3@xxxxxx Quote: >I have a function to read a binary file. I now need to convert the binary >to > a string. Does someone by chance have a function that does this? If so > could > you please post it, or show me an alternate method, or show me how I can > tweak my code so far (see below) to return a string from the original > binary? > > Function GetBinaryFileStream(argFullName) > Const adTypeBinary = 1 > Dim oBinaryStream > Set oBinaryStream = CreateObject("ADODB.Stream") > oBinaryStream.Type = adTypeBinary > oBinaryStream.Open > oBinaryStream.LoadFromFile argFullName > GetBinaryFileStream = oBinaryStream.Read > End Function to 'read the manual' to make full use of this versatility. http://msdn.microsoft.com/en-us/library/ms677486.aspx is a good place to start. It has been a while since I played with this, but I think that between the last two stream-related statements in your function, you need to set the stream pointer to the first character in the stream and change the stream type from binary to text. There may also be requirements to have a certain combination of stream charset and the script's Locale (read about the Locale-related functions in the VBScript help file. Code like this takes care of the stream stuff: stream.position = 0 stream.type = 2 stream.charset = "x-ansi" I think the VBScript locale has to be set to 1033. For more info, do a groups.google search: http://groups.google.com/groups/sear....*&qt_s=Search -Paul Randall |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Convert Byte() to string Hi Mayayana, Thanks! Our internet Nazi's are blocking downloads of zip files so I can't get your Clsbin package at work; however, I will download it tonight at home and check it out, thanks for responding. "mayayana" wrote: Quote: > I have a class I wrote that uses Textstream > and provides full binary file functionality - > reading, writing, returning numeric values > represented by a series of bytes... the basic > things that one would want to do with a binary file. > > www.jsware.net/jsware/scripts.php5#bints > > Textstream can do it all. You just have to be > careful of how you handle data that might contain > nulls. > A string, a stream and an array are not really > different things, so I don't know what you mean > by converting a binary file to string. Textstream > will read it out as a string, and that string can be > handled, or written to a new file, but you can't > "look at it too closely" unless you convert the nulls. > > Quote: > > I have a function to read a binary file. I now need to convert the binary Quote: > > a string. Does someone by chance have a function that does this? If so Quote: > > you please post it, or show me an alternate method, or show me how I can > > tweak my code so far (see below) to return a string from the original Quote: > > > > Function GetBinaryFileStream(argFullName) > > Const adTypeBinary = 1 > > Dim oBinaryStream > > Set oBinaryStream = CreateObject("ADODB.Stream") > > oBinaryStream.Type = adTypeBinary > > oBinaryStream.Open > > oBinaryStream.LoadFromFile argFullName > > GetBinaryFileStream = oBinaryStream.Read > > End Function > > > > Thanks much in advance. > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Convert Byte() to string Hi Paul, Thanks for the link and your response; I will endeavor to read the manual; it's just that immediate gratification is so much more satisfying (not to mention deadlines of course)...don't you think? ; ) "Paul Randall" wrote: Quote: > > "XP" <XP@xxxxxx> wrote in message > news:9747CDDE-1451-40BD-AE0A-D5E70F3A52B3@xxxxxx Quote: > >I have a function to read a binary file. I now need to convert the binary > >to > > a string. Does someone by chance have a function that does this? If so > > could > > you please post it, or show me an alternate method, or show me how I can > > tweak my code so far (see below) to return a string from the original > > binary? > > > > Function GetBinaryFileStream(argFullName) > > Const adTypeBinary = 1 > > Dim oBinaryStream > > Set oBinaryStream = CreateObject("ADODB.Stream") > > oBinaryStream.Type = adTypeBinary > > oBinaryStream.Open > > oBinaryStream.LoadFromFile argFullName > > GetBinaryFileStream = oBinaryStream.Read > > End Function > You are half way there. The ADODB.Stream is quite versatile, but you have > to 'read the manual' to make full use of this versatility. > http://msdn.microsoft.com/en-us/library/ms677486.aspx is a good place to > start. > > It has been a while since I played with this, but I think that between the > last two stream-related statements in your function, you need to set the > stream pointer to the first character in the stream and change the stream > type from binary to text. There may also be requirements to have a certain > combination of stream charset and the script's Locale (read about the > Locale-related functions in the VBScript help file. > > Code like this takes care of the stream stuff: > stream.position = 0 > stream.type = 2 > stream.charset = "x-ansi" > > I think the VBScript locale has to be set to 1033. > > For more info, do a groups.google search: > http://groups.google.com/groups/sear....*&qt_s=Search > > -Paul Randall > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Convert Byte() to string > Quote: > Thanks! Our internet Nazi's are blocking downloads of zip files sure that you have such a restriction. I try to block "download helpers" because they're nearly all sloppy -- and unnecessary -- programs that download multiple copies of everything. (I started the blocking one day after someone using what I think was GetRight downloaded 36MB worth of a 300KB file. Now GetRight just calls the server, repeatedly to get another 403 response. It will call every 6 seconds, sometimes for hours!) So if you were using Download Accelerator, GetRight, Free Download Manager, etc., you'd probably get a 403 (access forbidden) when trying to download the zip. In fact, people using FDM are unfortunately blocked from almost the entire site, including webpages, due to the way that FDM hijacks the IE userAgent string for advertising purposes. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Convert Byte() to string "mayayana" <mayaXXyana@xxxxxx> wrote in message news:eOhfMa89IHA.4536@xxxxxx Quote: Quote: > > >> Thanks! Our internet Nazi's are blocking downloads of zip files > It could be my site, too, unless you know for > sure that you have such a restriction. I try to > block "download helpers" because they're nearly > all sloppy -- and unnecessary -- programs that > download multiple copies of everything. (I started the > blocking one day after someone using what I think > was GetRight downloaded 36MB worth of a 300KB file. > Now GetRight just calls the server, repeatedly to get > another 403 response. It will call every 6 seconds, > sometimes for hours!) > > So if you were using > Download Accelerator, GetRight, Free Download > Manager, etc., you'd probably get a 403 (access > forbidden) when trying to download the zip. In fact, > people using FDM are unfortunately blocked from almost > the entire site, including webpages, due to the way that > FDM hijacks the IE userAgent string for advertising > purposes. Do you know of any way for the end user to learn about how badly the helper is hurting to web site being accessed? -Paul Randall |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Convert Byte() to string Yes, I like the immediate gratification too -- at least some code that I can run and see that it actually does what I want. In this case, I don't have that to give you. The google search link I gave you gets you to a specific thread that talks about this and has some code. If you search for some of the key words used in this section of my response: Quote: Quote: >> stream.position = 0 >> stream.type = 2 >> stream.charset = "x-ansi" copy and paste to get your job done. Its been a while, so I don't remember the details of what was posted. -Paul Randall "XP" <XP@xxxxxx> wrote in message news:E02BF9ED-52D2-43B6-BABB-71E9EDC6CD20@xxxxxx Quote: > Hi Paul, > > Thanks for the link and your response; I will endeavor to read the manual; > it's just that immediate gratification is so much more satisfying (not to > mention deadlines of course)...don't you think? ; ) > > > "Paul Randall" wrote: > Quote: >> >> "XP" <XP@xxxxxx> wrote in message >> news:9747CDDE-1451-40BD-AE0A-D5E70F3A52B3@xxxxxx Quote: >> >I have a function to read a binary file. I now need to convert the >> >binary >> >to >> > a string. Does someone by chance have a function that does this? If so >> > could >> > you please post it, or show me an alternate method, or show me how I >> > can >> > tweak my code so far (see below) to return a string from the original >> > binary? >> > >> > Function GetBinaryFileStream(argFullName) >> > Const adTypeBinary = 1 >> > Dim oBinaryStream >> > Set oBinaryStream = CreateObject("ADODB.Stream") >> > oBinaryStream.Type = adTypeBinary >> > oBinaryStream.Open >> > oBinaryStream.LoadFromFile argFullName >> > GetBinaryFileStream = oBinaryStream.Read >> > End Function >> You are half way there. The ADODB.Stream is quite versatile, but you >> have >> to 'read the manual' to make full use of this versatility. >> http://msdn.microsoft.com/en-us/library/ms677486.aspx is a good place to >> start. >> >> It has been a while since I played with this, but I think that between >> the >> last two stream-related statements in your function, you need to set the >> stream pointer to the first character in the stream and change the stream >> type from binary to text. There may also be requirements to have a >> certain >> combination of stream charset and the script's Locale (read about the >> Locale-related functions in the VBScript help file. >> >> Code like this takes care of the stream stuff: >> stream.position = 0 >> stream.type = 2 >> stream.charset = "x-ansi" >> >> I think the VBScript locale has to be set to 1033. >> >> For more info, do a groups.google search: >> http://groups.google.com/groups/sear....*&qt_s=Search >> >> -Paul Randall >> >> >> |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Convert Byte() to string Quote: > Thanks for this info on the "helpers". > Do you know of any way for the end user to learn about how badly the Quote: > is hurting to web site being accessed? > my only experience is with my own site. I like to read the server "raw" logs daily, to see where people linked from, find out when I have bad links, etc. That's how I started seeing the problem of download helpers. I don't know how much the end user can know. I send a 403 to helpers on my site, but none of the helper programs seems to be designed to recognize a 403 response. So there's no way for me to tell people why they're being blocked. As I understand it, helper programs originated with dial-up, as a way to make sure that a download didn't get dropped partway through. They typically work by opening numerous connections to the server, each requesting only part of the download file. That's a somewhat questionable logic with highspeed, except when one is downloading something like a 700MB CD ISO. And it also, often, doesn't work anyway because many servers won't allow multiple connections from the same IP. But beyond the issue of their real usefulness, from reading my logs I find that helpers usually download several times the bytage of a file. On my own site I have few downloads over 100 KB, yet I often see people on highspeed connections downloading a 50KB file in 5 or 6 pieces. By the time it's done they've downloaded maybe 150 KB total. Or sometimes they just download the whole file numerous times within a few seconds. Often they send the server a browser userAgent on the first download and then download several more times with a custom helper userAgent string. Ironically, people don't notice because with highspeed it only takes a few seconds either way. I often wonder what people experience when they've downloaded successfully, say, twice, and were blocked four times, all within 8 seconds. Did they get the file or do they see it as blocked? ![]() The problem for webmasters is 1) excess traffic that's unnecessary and 2) difficulty counting actual downloads. I can't identify all helpers with certainty because they vary in how they identify themselves to the server. The popular ones like FDM and Download Accelerator seem to be minor nuisances, downloading 2-6 copies instead of 1. I have reason to believe that GetRight is by far the worst, calling the server over and over again, often hundreds of times. (GetRight shows a dummy userAgent, so I had to identify it based on several bits of circumstantial evidence.) I don't know whether it's just badly designed or whether maybe it's outdated. The behavior makes no sense. But in general all of the helpers I've seen seem to be poorly designed in that they download multiples, clearly not keeping track of what they're doing. (And in most cases these are multiple downloads with a 200 code, not a 206. In other words, they're not downloading pieces. They're downloading the whole thing redundantly.) Another annoyance is the programs that download one of everything linked from a page. I suspect the people who do that are probably also the ones who never get around to looking at what they've downloaded. They're too busy hoarding more files. But those programs (scrapers?) at least seem to work properly. I seldom see a "scraper" download more than it needs to. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Read Byte Array into String for Delimiting? | .NET General | |||
| Convert to & from base64 String | PowerShell | |||
| convert int to numeric (formatted) string | .NET General | |||
| Convert Byte to Binary | PowerShell | |||
| HowTo: Convert int/Byte/Byte[] to Hex | PowerShell | |||