0

I am facing an issue where we are fetching the archive data (zip data) as string from blob. The string shows in double byte string (e.g. 'P'#0'K'#0#3#) and hence the zipforge that we use for extracting fails with Archive Error : 0035. So to overcome this issue, i tried to retrieve the data using the following code snippet (found in stackoverflow) and i get single byte string and i am able to extract the data.

      bStream := fld.Dataset.CreateBlobStream(fld, bmRead);
      try
        SetLength(BlobResult, bStream.Size);
        bStream.Read(BlobResult[1], bStream.Size);
      finally
        bStream.Free;
      end;

But now if the apply the above code snippet in blob created in Delphi 2007 then i get the garbage value and hence not able to extract the data. In this case Blob.asString looks good and extractions works fine

I would like to ask as how to safely get the blob data as a string so that i would be able to extract it without any issue.

Edit:- I am editing this question to add more information. Actually problem lies with the way i am getting the blob field value which has null character (#0) in it. I am getting each character as a double byte with null appended with each character. Even if i read it as a array of bytes, i get this null character and where the zipforge is failed to extract because it is not expecting this null character. Above code snippet works when we pass the appropriate string type (ansistring (in case of stream with no null character), string if the string have null character) while reading from the stream.

For you information, the field type which i get when i read the value is ftOraBlob as i am using oracle database.

  • 2
    A zip file is **not** a string. It's binary content. – Olivier May 06 '20 at 08:44
  • @Olivier i agree it is binary content but can be retrieved as a string. – shekhar keshri May 06 '20 at 08:55
  • 2
    But don't do it. It makes no sense. – Olivier May 06 '20 at 09:03
  • 1
    It's not usable as a string. You need to read it as binary data insetad. You can protest that it *can be retrieved as a string* all you want, but you're not going to get anywhere until you stop doing that and read it correctly as binary data. There is no *safely bet the blob data as a string* and *extract it without any issue*. You can extract it without any issue if you read it properly as binary data. ZipForge is expecting it to be binary, not text, and you're going to just keep banging your head against the wall until you accept that fact. Use a TMemoryStream instead. – Ken White May 07 '20 at 00:37
  • 1
    Or just use `TBlobStream.Memory` instead, which is already binary for a blob field. – Ken White May 07 '20 at 00:45

0 Answers0