Пример #1
0
        /// <summary>
        /// Delete a file inside datafile and all metadata related
        /// </summary>
        public bool Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            S3NoSqlFileInfo file = FindById(id);

            if (file == null)
            {
                return(true);
            }

            file.DeleteData();

            // remove file reference in _files
            var d = m_Engine.Delete(FILE, Query.EQ("_id", id));

            // if not found, just return false
            if (d == 0)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Upload a file based on stream data
        /// </summary>
        public S3NoSqlFileInfo Upload(string id, string filename, Stream stream)
        {
            // checks if file exists
            var file = this.FindById(id);

            if (file == null)
            {
                file = new S3NoSqlFileInfo(m_Engine, id, filename ?? id);

                // insert if new
                m_Engine.Insert(FILE, file.AsDocument);
            }

            // copy stream content to litedb file stream
            stream.CopyTo(file.OpenWriteData());

            return(file);
        }
Пример #3
0
        /// <summary>
        /// Open/Create new file storage and returns linked Stream to write operations
        /// </summary>
        public S3NoSqlFileInfo OpenWrite(string id, string filename, BsonDocument metadata = null)
        {
            // checks if file exists
            var file = this.FindById(id);

            if (file == null)
            {
                file = new S3NoSqlFileInfo(m_Engine, id, filename ?? id);

                // insert if new
                m_Engine.Insert(FILE, file.AsDocument);
            }

            // update metadata if passed
            if (metadata != null)
            {
                file.Metadata = metadata;
            }

            return(file);
        }