The solution I chose to use was to use a Regex against the ResponseStream available when you do a GetObject call. That way I'm downloading data, but it isn't being stored on my computer.
Here is the main bit of code for searching the objects contents:
private void SearchObjectForString(AmazonS3 amazonS3, string bucketName, string key, string searchString)
{
Cursor.Current = Cursors.WaitCursor;
// Issue call
var request = new GetObjectRequest();
request.BucketName = bucketName;
request.Key = key;
using (var response = amazonS3.GetObject(request))
{
using (var reader = new StreamReader(response.ResponseStream))
{
string line;
var rgx = new Regex(searchString, RegexOptions.IgnoreCase);
while ((line = reader.ReadLine()) != null)
{
Application.DoEvents();
if (cancelled)
{
Cursor.Current = Cursors.Default;
return;
}
var matches = rgx.Matches(line);
if (matches.Count > 0)
{
lstResults.Items.Add(string.Format("{0}/{1}:{2}", request.BucketName, request.Key, line));
}
}
}
}
Cursor.Current = Cursors.Default; }
No comments:
Post a Comment