If you have a blob in Azure Storage that you want to have a look at first before deciding whether to download it or not you can open up a stream from it and use a StreamReader to read as many rows as you want from it.

In my case I just wanted to have a look at the initial header row to try and determine what type of file it was before deciding on where to download it.

public async Task<string> GetBlobFileTypeAsync(CloudBlockBlob blob)
{
	using (Stream blobStream = await blob.OpenReadAsync())
	{
		using (StreamReader blobStreamReader = new StreamReader(blobStream))
		{
			string header = await blobStreamReader.ReadLineAsync();
			
			if (header == "idtype,idvalue,timestamp,type,domain,ipaddress,eventid")
			{
				return "events";
			}
			else if (header == "idtype,idvalue,eventid,name,value")
			{
				return "attributes";
			}
			else
			{
				throw new NotImplementedException("Unknown file structure");
			}
		}
	}
}

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *