Allow user to specify Guid

Aug 5, 2011 at 1:19 PM

I'd like to propose a simple change which would allow files to be placed at pre-specified locations. This would allow someone to store some specific information at a pre-determined, specific location.  It would make the library much more extendible by allowing someone to have a Meta-Data file with an ID of Guid.Empty for example.

In EntryInfo, change the first constructor to the following pair of constructors.

        internal EntryInfo(string fileName):this(Guid.NewGuid(), fileName)
        {}

        internal EntryInfo(Guid id, string fileName)
        {
            _id = id;
            _fileName = Path.GetFileName(fileName);
            _mimeType = MimeTypeConverter.Convert(Path.GetExtension(_fileName));
            _fileLength = 0;
        }

And add this additional method to the FileDB class
        /// <summary>
        /// Store a stream inside database
        /// </summary>
        /// <param name="id">An ID which can be used to retrieve the file</param>
        /// <param name="fileName">Just a name of file, to get future reference (eg: MyPhoto.jpg)</param>
        /// <param name="input">Stream thats contains the file</param>
        /// <returns>EntryInfo with information store</returns>
        public EntryInfo Store(Guid id, string fileName, Stream input)
        {
            var entry = new EntryInfo(id, fileName);
            _engine.Write(entry, input);
            return entry;
        }
I'd really like commit permissions on this project so I could make additional changes (such as the OpenRead method)

Aug 26, 2011 at 9:21 PM

I would like that too, but I tried something similar to your changes and there is a problem when inserting the entry. If you insert the same entry twice (means: you are replacing the old entry with a new one) the system will thrown a FileDBException as both the old and the new GUIDs are equals.

Not sure about the implications of replacing the throw with a "return baseNode;"