{"record":{"id":"df7d8445a4b61a45","repo":"files-community/Files","slug":"can-t-open-zip-file-as-rw","errorCode":null,"errorMessage":"Can't open zip file as RW","messagePattern":"Can't open zip file as RW","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs","lineNumber":155,"sourceCode":"\t\t\t\t\t}\n\n\t\t\t\t\t//zipFile.IsStreamOwner = true;\n\t\t\t\t\tvar entry = zipFile.GetArchiveFileData(containerPath).FirstOrDefault(x => System.IO.Path.Combine(containerPath, x.FileName) == Path);\n\n\t\t\t\t\tif (entry.FileName is not null)\n\t\t\t\t\t{\n\t\t\t\t\t\tvar ms = new MemoryStream();\n\t\t\t\t\t\tawait zipFile.ExtractFileAsync(entry.Index, ms);\n\t\t\t\t\t\tms.Position = 0;\n\t\t\t\t\t\treturn new NonSeekableRandomAccessStreamForRead(ms, entry.Size)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tDisposeCallback = () => zipFile.Dispose()\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tthrow new NotSupportedException(\"Can't open zip file as RW\");\n\t\t\t}, ((IPasswordProtectedItem)this).RetryWithCredentialsAsync));\n\t\t}\n\t\tprivate IAsyncOperation<IRandomAccessStream> OpenWithEncodingAsync(FileAccessMode accessMode)\n\t\t{\n\t\t\treturn AsyncInfo.Run((cancellationToken) => SafetyExtensions.Wrap<IRandomAccessStream>(async () =>\n\t\t\t{\n\t\t\t\tbool rw = accessMode is FileAccessMode.ReadWrite;\n\t\t\t\tif (rw)\n\t\t\t\t\tthrow new NotSupportedException(\"Can't open zip file as RW\");\n\n\t\t\t\tusing var zipFile = new ZipFile(containerPath, StringCodec.FromEncoding(CurrentEncoding!));\n\n\t\t\t\tif (!string.IsNullOrEmpty(Credentials.Password))\n\t\t\t\t\tzipFile.Password = Credentials.Password;\n\n\t\t\t\tvar targetName = GetEntryRelativePath();\n\n\t\t\t\tforeach (ZipEntry entry in zipFile)","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/files-community/Files/blob/68c68a58d4d6a5f7197e07c8fff85cfd4279c78b/src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs#L137-L173","documentation":"In ZipStorageFile.OpenAsync, when the requested access is FileAccessMode.ReadWrite and the file is an inner zip entry (Path != containerPath, SevenZip branch), the code throws NotSupportedException(\"Can't open zip file as RW\"). ZIP entries are extracted into a transient MemoryStream that is read-only, so the implementation cannot honor a read-write handle back into the archive.","triggerScenarios":"Calling OpenAsync(FileAccessMode.ReadWrite) (or OpenAsync with the ReadWrite value) on a ZipStorageFile that represents an entry inside a ZIP (not the archive root). Also any OpenAsync(options) overload that forwards to this method with ReadWrite.","commonSituations":"An editor or save routine that opens a file for read-write editing directly on a zip entry, expecting in-place editing, instead of extracting first. Copy-and-edit flows that reuse the IStorageItem handle.","solutions":["Open with FileAccessMode.Read only for inner zip entries; for editing, extract the entry to a real file and edit that.","Check access mode at the call site and reject ReadWrite for archive entries before calling OpenAsync.","Use CopyAsync to materialize the entry into a real BaseStorageFile, then open that for read-write."],"exampleFix":"// before\nusing var stream = await zipEntryFile.OpenAsync(FileAccessMode.ReadWrite); // throws\n\n// after\nif (zipEntryFile is ZipStorageFile zf && zf.Path != /*containerPath*/) // inner entry\n    throw new InvalidOperationException(\"Zip entries are read-only; extract first.\");\nusing var stream = await zipEntryFile.OpenAsync(FileAccessMode.Read);","handlingStrategy":"validation","validationCode":"bool CanOpenRw(BaseStorageFile f) => f is not ZipStorageFile zf || zf.Path == /*containerPath*/;","typeGuard":"static bool IsZipEntry(BaseStorageFile f) => f is ZipStorageFile;","tryCatchPattern":"try { return await f.OpenAsync(FileAccessMode.ReadWrite); }\ncatch (NotSupportedException) { /* fall back to read-only or extract first */ }","preventionTips":["Never open inner zip entries ReadWrite; extract first.","Check the access mode and item type before OpenAsync.","Materialize entries via CopyAsync before editing."],"tags":["winrt","storage","zip","read-write","not-supported"],"backgroundTag":null,"analyzedSha":"68c68a58d4d6a5f7197e07c8fff85cfd4279c78b","analyzedAt":"2026-08-13T10:34:54.614Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}