示例#1
0
        public Task <BlobElement[]> ListAsync(string path, CancellationToken cancellationToken = default)
        {
            try
            {
                var fullPath = GetFullPath(path);

                var directories = Directory.GetDirectories(fullPath)
                                  .Select(d => BlobElement.CreateContainer(d, Path.GetFileName(d)));

                var files = Directory.GetFiles(fullPath)
                            .Select(d => BlobElement.CreateBlob(d, Path.GetFileName(d)));

                return(Task.FromResult(directories.Concat(files).ToArray()));
            }
            catch (DirectoryNotFoundException e)
            {
                throw new ContainerNotFoundException(path, e);
            }
        }
示例#2
0
        private IEnumerable <BlobElement> ListInternal(string[] pathSegments)
        {
            lock (_lock)
            {
                foreach (var blob in _blobs)
                {
                    var blobSegments = PathUtilities.GetSegments(blob.Key);
                    if (blobSegments.Length >= pathSegments.Length + 1)
                    {
                        if (blobSegments.Length == pathSegments.Length + 1 &&
                            blobSegments.Take(blobSegments.Length - 1).SequenceEqual(pathSegments))
                        {
                            yield return(BlobElement.CreateBlob(blob.Key, blobSegments.Last()));
                        }

                        for (var i = 1; i < blobSegments.Length; i++)
                        {
                            var path = string.Join("/", blobSegments.Take(i));
                            yield return(BlobElement.CreateContainer(path, blobSegments.Skip(i - 1).First()));
                        }
                    }
                }
            }
        }