-2

I have some BLOBS column in a MySQL database. I want to unpack, read it and the save unpacked data into another table.

Is there a library for unpacking MySQL BLOBS in c#? I have tried using code but was wondering if there was any free library for the same.

Ritesh
  • 9
  • 5
  • What do you mean by "unpacking blobs"? You can select blob data from a database like any other binary data. – David Sep 13 '17 at 17:07
  • Just I want to decrept the BLOB data which is in Key Value format. – Ritesh Sep 13 '17 at 17:20
  • I doubt there's any library which would arbitrarily know what format you're storing your data in. Do you know the format of your data? If it's some kind of known standard, then look for libraries which can operate on that data format. It has nothing to do with whether or not you store it in MySQL. – David Sep 13 '17 at 17:22
  • data is in BLOB format in MYSQL but contents is long text array format. – Ritesh Sep 13 '17 at 17:33
  • 1
    *What* key-value format? If by "unpacking" you actually mean "unserializing" then it's a matter of figuring out how it was serialized in the first place. `BLOB` is not a format, it's a column type. – tadman Sep 13 '17 at 17:33
  • @Ritesh: And *what is* "long text array format"? You seem to be under the impression that computers can somehow intuitively understand data by what that data *looks like*. Humans do that, computers don't. To parse your data you will need to know what *actual format* that data is in. "Blob" is not a format. "Text array" is not a format. Unless there's some standard that you're following, your data is in your own custom format. There is no library out there which understands your custom format that only you use. – David Sep 13 '17 at 17:36
  • EmpActivity: [{"start"=>"0.004", "stop"=>0.004}, {"start"=>"0.004", "stop"=>42.153}, – Ritesh Sep 13 '17 at 17:46
  • EmpActivity is column name and above is the data in the same column. I want to read and get all data and store it into different table – Ritesh Sep 13 '17 at 17:48
  • @Ritesh: If you have a custom format, you will need to decode it yourself. Read the byte array of data from the database, convert it to a string using whatever character encoding you used to store it, then parse that string into your data structure. – David Sep 13 '17 at 17:49
  • Thanks David and tadman for your time. I was wondering if there could be any library in c#. – Ritesh Sep 13 '17 at 17:53

1 Answers1

0

Hi you can use MessagePack library for unpacking the blob data into json format.

 byte[] test = (Byte[])reader[0];
    Console.WriteLine("============================RAW===========================================");                            
    string text = System.Text.UnicodeEncoding.UTF8.GetString(test);
    Console.WriteLine(text);
    Console.WriteLine("============================UNPACKED======================================");
    var json = MessagePackSerializer.ToJson(test);
Pushpendra
  • 16
  • 5