internal static IDictionary <string, object> InstallAttachmentBodies(IDictionary <string
                                                                                          , object> attachments, Database database)
        {
            IDictionary <string, object> updatedAttachments = new Dictionary <string, object>();

            foreach (string name in attachments.Keys)
            {
                object value = attachments.Get(name);
                if (value is Couchbase.Lite.Attachment)
                {
                    Couchbase.Lite.Attachment    attachment      = (Couchbase.Lite.Attachment)value;
                    IDictionary <string, object> metadataMutable = new Dictionary <string, object>();
                    metadataMutable.PutAll(attachment.GetMetadata());
                    InputStream body = attachment.GetBodyIfNew();
                    if (body != null)
                    {
                        // Copy attachment body into the database's blob store:
                        BlobStoreWriter writer = BlobStoreWriterForBody(body, database);
                        metadataMutable.Put("length", (long)writer.GetLength());
                        metadataMutable.Put("digest", writer.MD5DigestString());
                        metadataMutable.Put("follows", true);
                        database.RememberAttachmentWriter(writer);
                    }
                    updatedAttachments.Put(name, metadataMutable);
                }
                else
                {
                    if (value is AttachmentInternal)
                    {
                        throw new ArgumentException("AttachmentInternal objects not expected here.  Could indicate a bug"
                                                    );
                    }
                    else
                    {
                        if (value != null)
                        {
                            updatedAttachments.Put(name, value);
                        }
                    }
                }
            }
            return(updatedAttachments);
        }
        public void TestStreamAttachmentBlobStoreWriter()
        {
            var attachments = database.Attachments;
            var blobWriter = new BlobStoreWriter(attachments);
            var testBlob = "foo";
            blobWriter.AppendData(Runtime.GetBytesForString(testBlob));
            blobWriter.Finish();

            var sha1Base64Digest = "sha1-C+7Hteo/D9vJXQ3UfzxbwnXaijM=";
            Assert.AreEqual(blobWriter.SHA1DigestString(), sha1Base64Digest);
            Assert.AreEqual(blobWriter.MD5DigestString(), "md5-rL0Y20zC+Fzt72VPzMSk2A==");

            // install it
            blobWriter.Install();
            // look it up in blob store and make sure it's there
            var blobKey = new BlobKey(sha1Base64Digest);
            var blob = attachments.BlobForKey(blobKey);
            Assert.IsTrue(Arrays.Equals(Runtime.GetBytesForString(testBlob).ToArray(), blob));
        }
Beispiel #3
0
        public virtual void TestStreamAttachmentBlobStoreWriter()
        {
            BlobStore       attachments = database.GetAttachments();
            BlobStoreWriter blobWriter  = new BlobStoreWriter(attachments);
            string          testBlob    = "foo";

            blobWriter.AppendData(Sharpen.Runtime.GetBytesForString(new string(testBlob)));
            blobWriter.Finish();
            string sha1Base64Digest = "sha1-C+7Hteo/D9vJXQ3UfzxbwnXaijM=";

            NUnit.Framework.Assert.AreEqual(blobWriter.SHA1DigestString(), sha1Base64Digest);
            NUnit.Framework.Assert.AreEqual(blobWriter.MD5DigestString(), "md5-rL0Y20zC+Fzt72VPzMSk2A=="
                                            );
            // install it
            blobWriter.Install();
            // look it up in blob store and make sure it's there
            BlobKey blobKey = new BlobKey(sha1Base64Digest);

            byte[] blob = attachments.BlobForKey(blobKey);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(Sharpen.Runtime.GetBytesForString(testBlob
                                                                                          , Sharpen.Extensions.GetEncoding("UTF-8")), blob));
        }
 internal void RememberAttachmentWriter (BlobStoreWriter writer)
 {
     var digest = writer.MD5DigestString();
     PendingAttachmentsByDigest[digest] = writer;
 }
Beispiel #5
0
		internal void RememberAttachmentWriter(BlobStoreWriter writer)
		{
			GetPendingAttachmentsByDigest().Put(writer.MD5DigestString(), writer);
		}
        public void TestStreamAttachmentBlobStoreWriter()
        {
            var attachments = database.Attachments;
            var blobWriter = new BlobStoreWriter(attachments);
            var testBlob = "foo";
            blobWriter.AppendData(Runtime.GetBytesForString(testBlob));
            blobWriter.Finish();

            var sha1Base64Digest = "sha1-C+7Hteo/D9vJXQ3UfzxbwnXaijM=";
            Assert.AreEqual(blobWriter.SHA1DigestString(), sha1Base64Digest);
            Assert.AreEqual(blobWriter.MD5DigestString(), "md5-rL0Y20zC+Fzt72VPzMSk2A==");

            // install it
            blobWriter.Install();
            // look it up in blob store and make sure it's there
            var blobKey = new BlobKey(sha1Base64Digest);
            var blob = attachments.BlobForKey(blobKey);
            Assert.IsTrue(Arrays.Equals(Runtime.GetBytesForString(testBlob).ToArray(), blob));
        }
		public virtual void TestStreamAttachmentBlobStoreWriter()
		{
			BlobStore attachments = database.GetAttachments();
			BlobStoreWriter blobWriter = new BlobStoreWriter(attachments);
			string testBlob = "foo";
			blobWriter.AppendData(Sharpen.Runtime.GetBytesForString(new string(testBlob)));
			blobWriter.Finish();
			string sha1Base64Digest = "sha1-C+7Hteo/D9vJXQ3UfzxbwnXaijM=";
			NUnit.Framework.Assert.AreEqual(blobWriter.SHA1DigestString(), sha1Base64Digest);
			NUnit.Framework.Assert.AreEqual(blobWriter.MD5DigestString(), "md5-rL0Y20zC+Fzt72VPzMSk2A=="
				);
			// install it
			blobWriter.Install();
			// look it up in blob store and make sure it's there
			BlobKey blobKey = new BlobKey(sha1Base64Digest);
			byte[] blob = attachments.BlobForKey(blobKey);
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(Sharpen.Runtime.GetBytesForString(testBlob
				, Sharpen.Extensions.GetEncoding("UTF-8")), blob));
		}