{"record":{"id":"b911045d19ed4c6f","repo":"a-b-street/abstreet","slug":"writing-binary-files-on-web-unsupported","errorCode":null,"errorMessage":"writing binary files on web unsupported","messagePattern":"writing binary files on web unsupported","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"map_gui/src/tools/ui.rs","lineNumber":111,"sourceCode":"                } else {\n                    Err(anyhow!(\"no file chosen to save\"))\n                };\n\n                #[cfg(target_arch = \"wasm32\")]\n                let result = {\n                    // Hide an unused warning\n                    let _ = builder;\n\n                    // TODO No file save dialog on WASM until\n                    // https://developer.mozilla.org/en-US/docs/Web/API/Window/showSaveFilePicker\n                    match write {\n                        FileSaverContents::String(string) => {\n                            abstio::write_file(filename.clone(), string)\n                        }\n                        FileSaverContents::Bytes(_bytes) => {\n                            // We need to use write_file (which downloads a file), but encode\n                            // binary data the right way\n                            Err(anyhow!(\"writing binary files on web unsupported\"))\n                        }\n                    }\n                };\n\n                let wrap: Box<dyn Send + FnOnce(&A) -> Result<String>> =\n                    Box::new(move |_: &A| result);\n                Ok(wrap)\n            }),\n            outer_progress_rx,\n            inner_progress_rx,\n            \"Waiting for a file to be chosen\",\n            on_load,\n        )\n    }\n\n    // Popup a success or failure message after\n    pub fn with_default_messages<A: 'static + AppLike>(\n        ctx: &mut EventCtx,","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/map_gui/src/tools/ui.rs#L93-L129","documentation":"FileSaver::new_state's wasm branch downloads files via abstio::write_file, which can only handle text; when the payload is FileSaverContents::Bytes it immediately returns anyhow!(\"writing binary files on web unsupported\"). Binary saving on web would need encoding (e.g. base64) that isn't implemented.","triggerScenarios":"Attempting to save binary data (Bytes variant, e.g. a downloaded map binary or raw image) from the web build via the FileSaver UI.","commonSituations":"Running abstreet in a browser and triggering an export that stores Bytes instead of String; a feature added for native saving then exercised on web.","solutions":["Convert binary data to a text-safe format (base64) before saving on web, then decode on load","Save only String contents on web, or gate binary-saving features to native builds","Extend abstio::write_file to support Blobs/arraybuffers for binary downloads"],"exampleFix":"// before\nFileSaverContents::Bytes(_bytes) => Err(anyhow!(\"writing binary files on web unsupported\")),\n// after\nFileSaverContents::Bytes(bytes) => {\n    let b64 = base64::encode(&bytes);\n    abstio::write_file(filename, b64)\n}","handlingStrategy":"validation","validationCode":"// guard before saving binary data on web\nif matches!(contents, FileSaverContents::Bytes(_)) && cfg!(target_arch = \"wasm32\") {\n    // encode to base64 or block the feature\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = saver.consume() {\n    if e.to_string().contains(\"binary files on web unsupported\") {\n        // fall back to text encoding or notify user\n    }\n}","preventionTips":["Design export features to emit text-safe payloads usable on web","Feature-gate binary exports to native builds","Implement a base64/blob path in abstio before enabling binary saves on web"],"tags":["wasm","file-save","binary","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}