Exemplo n.º 1
0
 public void MyTest_SharpZipLibFileSystem()
 {
     using (var fileStream = System.IO.File.Create(@"D:\workPrj\aa.zip"))
         using (var fileSystem = SharpZipLibFileSystem.Create(fileStream))
         {
             WriteContents(fileSystem);
         }
 }
Exemplo n.º 2
0
        public RuntimeEngine(string path, IKernel kernel, IMyLib myLib)
        {
            _path   = path;
            _kernel = kernel;
            _myLib  = myLib;

            _package = SharpZipLibFileSystem.Open(_myLib.Storage.ReadFileAsStream(Path.Combine(_myLib.CurrentDirectory, path)));
            kernel.MountDisk(_package, "/mnt/" + path);

            _storage = new StorageService();

            Name = "Test";
        }
Exemplo n.º 3
0
        public RuntimeEngine(string path, IKernel kernel, IMyLib myLib)
        {
            _path   = path;
            _kernel = kernel;

            _package = SharpZipLibFileSystem.Open(myLib.Storage.ReadFileAsStream(Path.Combine(myLib.CurrentDirectory, path)));
            kernel.MountDisk(_package, "/mnt/" + path);

            _storage = new StorageService(kernel.Drive("/mnt/" + path));

            string data = _storage.ReadFileAsString("/app.json");

            _manifest = JsonConvert.DeserializeObject <ApplicationManifest>(data);
            Name      = "app." + _manifest.Name;
        }
Exemplo n.º 4
0
        void WriteZipFSTest()
        {
            var dirPath  = FileSystemPath.Root.AppendDirectory("dir");
            var filePath = dirPath.AppendFile("file.txt");

            string zipFileName = @".\newtest.zip";

            if (System.IO.File.Exists(zipFileName))
            {
                System.IO.File.Delete(zipFileName);
            }

            using (var zipFileSystem =
                       SharpZipLibFileSystem.Open(System.IO.File.Open(zipFileName, FileMode.OpenOrCreate)))
            {
                using (var transaction = zipFileSystem.OpenWriteTransaction())
                {
                    zipFileSystem.CreateDirectory(dirPath);
                    using (var stream = zipFileSystem.CreateFile(filePath))
                    {
                        using (StreamWriter sw = new StreamWriter(stream))
                        {
                            sw.Write("hello zip");
                        }
                    }
                }

                ;
                // TODO : check if written sucessfully

                Assert.True(zipFileSystem.Exists(filePath));
                using (var xStream = zipFileSystem.OpenFile(filePath, FileAccess.Read))
                {
                    var readContent = new byte[128];
                    int read        = xStream.Read(readContent, 0, readContent.Length);

                    Assert.Equal(9, read);
                    string value = Encoding.ASCII.GetString(readContent, 0, read);
                    Assert.Equal("hello zip", value);
                    // Trying to read beyond end of file should return 0.
                    Assert.Equal(0, xStream.Read(readContent, 0, readContent.Length));
                }
            }
        }
Exemplo n.º 5
0
        public void Initialize()
        {
            var memoryStream = new MemoryStream();

            zipStream = memoryStream;
            var zipOutput = new ZipOutputStream(zipStream);

            var fileContentString = "this is a file";
            var fileContentBytes  = Encoding.ASCII.GetBytes(fileContentString);

            zipOutput.PutNextEntry(new ZipEntry("textfileA.txt")
            {
                Size = fileContentBytes.Length
            });
            zipOutput.Write(fileContentBytes);
            zipOutput.PutNextEntry(new ZipEntry("directory/fileInDirectory.txt"));
            zipOutput.Finish();

            memoryStream.Position = 0;
            fileSystem            = SharpZipLibFileSystem.Open(zipStream);
        }
Exemplo n.º 6
0
        private static void ConfigureStaticFilesHosting(IAppBuilder app)
        {
            const string appZipResource = "dashboard-app.zip";

            var appZipEmbeddedResourceName = Assembly.GetEntryAssembly().GetManifestResourceNames().FirstOrDefault(p => p.EndsWith(appZipResource));

            if (appZipEmbeddedResourceName == null)
            {
                throw new NullReferenceException("Could not find dashboard-app.zip in the entry assembly. Please make sure dashboard-app.zip is included in your jobbr server project and build action is set to Embedded Resource");
            }

            var stream        = Assembly.GetEntryAssembly().GetManifestResourceStream(appZipEmbeddedResourceName);
            var zipFileSystem = SharpZipLibFileSystem.Open(stream);

            var wrapper = new FileSystemWrapper(zipFileSystem);

            var options = new FileServerOptions
            {
                EnableDefaultFiles = true,
                FileSystem         = wrapper,
                StaticFileOptions  =
                {
                    FileSystem            = wrapper,
                    ServeUnknownFileTypes = true
                },
                DefaultFilesOptions =
                {
                    DefaultFileNames = new[]
                    {
                        "index.html"
                    }
                }
            };

            app.UseFileServer(options);
        }
Exemplo n.º 7
0
        void ReadZipFS()
        {
            FileSystemPath MemRootFilePath = FileSystemPath.Root.AppendFile("x");
            var            zipFileSystem   = SharpZipLibFileSystem.Open(System.IO.File.Open(@".\test.zip", FileMode.Open));

            // File shouldn’t exist prior to creation.
            Assert.False(zipFileSystem.Exists(MemRootFilePath));

            // File should still exist and have content.
            var file = FileSystemPath.Parse("/file");

            Assert.True(zipFileSystem.Exists(file));
            using (var xStream = zipFileSystem.OpenFile(file, FileAccess.Read))
            {
                var readContent = new byte[128];
                int read        = xStream.Read(readContent, 0, readContent.Length);

                Assert.Equal(4, read);
                string value = Encoding.ASCII.GetString(readContent, 0, read);
                Assert.Equal("test", value);
                // Trying to read beyond end of file should return 0.
                Assert.Equal(0, xStream.Read(readContent, 0, readContent.Length));
            }
        }
 public void Initialize()
 {
     fileStream = System.IO.File.OpenRead("SharpZipLib/Content/test.zip");
     fileSystem = SharpZipLibFileSystem.Open(fileStream);
 }
 public void Initialize()
 {
     CreateInitialZipStream();
     fileSystem    = SharpZipLibFileSystem.Open(zipStream, zipPassword);
     badFileSystem = SharpZipLibFileSystem.Open(zipStream, "wrongpassword");
 }