0
votes

The ADLS .NET SDK has some good examples for reading and creating text files. This uses StreamReader and this shouldn't be used with binary files. I tried using BinaryReader but have been unsuccessful.

https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-net-sdk

//Read file contents
using (var readStream = new StreamReader(client.GetReadStream(fileName)))
{
    string line;
    while ((line = readStream.ReadLine()) != null)
    {
        Console.WriteLine(line);
    }
}

Can the .NET SDK create/read binary? If so, are there any examples of doing this?

1

1 Answers

1
votes

Can the .NET SDK create/read binary? If so, are there any examples of doing this?

Short answer is yes, please refer to the following demo code.

Create binary File

AdlsClient adlsClient = AdlsClient.CreateClient($"{datalakeAccount}.azuredatalakestore.net", clientCreds);
using (var stream = adlsClient.CreateFile("file name", IfExists.Overwrite))
{
    byte[] textByteArray = File.ReadAllBytes(@"local file path");
    stream.Write(textByteArray, 0, textByteArray.Length);
}

read binary file and write to local file

using (var filesream = adlsClient.GetReadStream("1.png"))

{               
     MemoryStream memorystream = new MemoryStream();
     filesream.CopyTo(memorystream);
     memorystream.Position = 0;
     File.WriteAllBytes(@"filename", memorystream.ToArray());         
}