Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Paul Irish | d890ac8 | 2025-07-16 19:49:24 | [diff] [blame^] | 31 | import * as Common from '../../core/common/common.js'; |
Kateryna Prokopenko | 380fdfa | 2022-03-16 16:39:32 | [diff] [blame] | 32 | import type * as Platform from '../../core/platform/platform.js'; |
Benedikt Meurer | 0048894 | 2025-06-17 17:52:25 | [diff] [blame] | 33 | import * as TextUtils from '../text_utils/text_utils.js'; |
Tim van der Lippe | 99aeaf3 | 2021-04-09 10:33:34 | [diff] [blame] | 34 | import * as Workspace from '../workspace/workspace.js'; |
Tim van der Lippe | 55cd4ef | 2020-01-23 17:31:39 | [diff] [blame] | 35 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 36 | export interface ChunkedReader { |
| 37 | fileSize(): number; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 38 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 39 | loadedSize(): number; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 40 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 41 | fileName(): string; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 42 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 43 | cancel(): void; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 44 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 45 | error(): DOMError|null; |
Tim van der Lippe | 0723204 | 2019-10-08 15:58:07 | [diff] [blame] | 46 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 47 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 48 | export class ChunkedFileReader implements ChunkedReader { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 49 | #file: File|null; |
| 50 | readonly #fileSizeInternal: number; |
| 51 | #loadedSizeInternal: number; |
Nikolay Vitkov | 17794ee | 2025-01-29 20:26:27 | [diff] [blame] | 52 | #streamReader: ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>>|null; |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 53 | readonly #chunkSize: number; |
| 54 | readonly #chunkTransferredCallback: ((arg0: ChunkedReader) => void)|undefined; |
| 55 | readonly #decoder: TextDecoder; |
| 56 | #isCanceled: boolean; |
| 57 | #errorInternal: DOMException|null; |
| 58 | #transferFinished!: (arg0: boolean) => void; |
| 59 | #output?: Common.StringOutputStream.OutputStream; |
| 60 | #reader?: FileReader|null; |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 61 | |
Alina Varkki | 2fc2ce8 | 2024-03-22 10:49:31 | [diff] [blame] | 62 | constructor(file: File, chunkSize?: number, chunkTransferredCallback?: ((arg0: ChunkedReader) => void)) { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 63 | this.#file = file; |
| 64 | this.#fileSizeInternal = file.size; |
| 65 | this.#loadedSizeInternal = 0; |
Alina Varkki | 2fc2ce8 | 2024-03-22 10:49:31 | [diff] [blame] | 66 | this.#chunkSize = (chunkSize) ? chunkSize : Number.MAX_VALUE; |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 67 | this.#chunkTransferredCallback = chunkTransferredCallback; |
| 68 | this.#decoder = new TextDecoder(); |
| 69 | this.#isCanceled = false; |
| 70 | this.#errorInternal = null; |
| 71 | this.#streamReader = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 72 | } |
| 73 | |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 74 | async read(output: Common.StringOutputStream.OutputStream): Promise<boolean> { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 75 | if (this.#chunkTransferredCallback) { |
| 76 | this.#chunkTransferredCallback(this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 77 | } |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 78 | |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 79 | if (this.#file?.type.endsWith('gzip')) { |
Paul Irish | d890ac8 | 2025-07-16 19:49:24 | [diff] [blame^] | 80 | const fileStream = this.#file.stream(); |
| 81 | const stream = Common.Gzip.decompressStream(fileStream); |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 82 | this.#streamReader = stream.getReader(); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 83 | } else { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 84 | this.#reader = new FileReader(); |
| 85 | this.#reader.onload = this.onChunkLoaded.bind(this); |
| 86 | this.#reader.onerror = this.onError.bind(this); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 87 | } |
| 88 | |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 89 | this.#output = output; |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 90 | void this.loadChunk(); |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 91 | |
Nikolay Vitkov | d36860c | 2025-02-19 17:50:27 | [diff] [blame] | 92 | return await new Promise(resolve => { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 93 | this.#transferFinished = resolve; |
Patrick Brosset | e65aaac | 2020-06-22 08:04:40 | [diff] [blame] | 94 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 95 | } |
| 96 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 97 | cancel(): void { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 98 | this.#isCanceled = true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | } |
| 100 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 101 | loadedSize(): number { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 102 | return this.#loadedSizeInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 103 | } |
| 104 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 105 | fileSize(): number { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 106 | return this.#fileSizeInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 107 | } |
| 108 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 109 | fileName(): string { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 110 | if (!this.#file) { |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 111 | return ''; |
| 112 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 113 | return this.#file.name; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 114 | } |
| 115 | |
Sigurd Schneider | 576ca9a | 2021-07-16 05:58:04 | [diff] [blame] | 116 | error(): DOMException|null { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 117 | return this.#errorInternal; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 118 | } |
| 119 | |
Jan Scheffler | 085122e | 2021-08-07 08:04:40 | [diff] [blame] | 120 | private onChunkLoaded(event: Event): void { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 121 | if (this.#isCanceled) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 122 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 123 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 125 | const eventTarget = (event.target as FileReader); |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 126 | if (eventTarget.readyState !== FileReader.DONE) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 127 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 128 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 129 | |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 130 | if (!this.#reader) { |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 134 | const buffer = (this.#reader.result as ArrayBuffer); |
| 135 | this.#loadedSizeInternal += buffer.byteLength; |
| 136 | const endOfFile = this.#loadedSizeInternal === this.#fileSizeInternal; |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 137 | void this.decodeChunkBuffer(buffer, endOfFile); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 138 | } |
| 139 | |
Jan Scheffler | 085122e | 2021-08-07 08:04:40 | [diff] [blame] | 140 | private async decodeChunkBuffer(buffer: ArrayBuffer, endOfFile: boolean): Promise<void> { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 141 | if (!this.#output) { |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 142 | return; |
| 143 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 144 | const decodedString = this.#decoder.decode(buffer, {stream: !endOfFile}); |
Alina Varkki | 2fc2ce8 | 2024-03-22 10:49:31 | [diff] [blame] | 145 | await this.#output.write(decodedString, endOfFile); |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 146 | if (this.#isCanceled) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 147 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 148 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 149 | if (this.#chunkTransferredCallback) { |
| 150 | this.#chunkTransferredCallback(this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 151 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 152 | |
| 153 | if (endOfFile) { |
Andrés Olivares | 435b3eb | 2022-10-17 11:46:39 | [diff] [blame] | 154 | void this.finishRead(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 155 | return; |
| 156 | } |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 157 | void this.loadChunk(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 158 | } |
| 159 | |
Andrés Olivares | 435b3eb | 2022-10-17 11:46:39 | [diff] [blame] | 160 | private async finishRead(): Promise<void> { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 161 | if (!this.#output) { |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 162 | return; |
| 163 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 164 | this.#file = null; |
| 165 | this.#reader = null; |
Andrés Olivares | 435b3eb | 2022-10-17 11:46:39 | [diff] [blame] | 166 | await this.#output.close(); |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 167 | this.#transferFinished(!this.#errorInternal); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 168 | } |
| 169 | |
Jan Scheffler | 085122e | 2021-08-07 08:04:40 | [diff] [blame] | 170 | private async loadChunk(): Promise<void> { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 171 | if (!this.#output || !this.#file) { |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 172 | return; |
| 173 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 174 | if (this.#streamReader) { |
| 175 | const {value, done} = await this.#streamReader.read(); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 176 | if (done || !value) { |
Alina Varkki | 2fc2ce8 | 2024-03-22 10:49:31 | [diff] [blame] | 177 | // Write empty string to inform of file end |
| 178 | await this.#output.write('', true); |
Nikolay Vitkov | d36860c | 2025-02-19 17:50:27 | [diff] [blame] | 179 | return await this.finishRead(); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 180 | } |
Tim van der Lippe | 2d9a95c | 2022-01-04 15:18:03 | [diff] [blame] | 181 | void this.decodeChunkBuffer(value.buffer, false); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 182 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 183 | if (this.#reader) { |
| 184 | const chunkStart = this.#loadedSizeInternal; |
| 185 | const chunkEnd = Math.min(this.#fileSizeInternal, chunkStart + this.#chunkSize); |
| 186 | const nextPart = this.#file.slice(chunkStart, chunkEnd); |
| 187 | this.#reader.readAsArrayBuffer(nextPart); |
Paul Irish | fe3cbe6 | 2021-04-13 20:51:19 | [diff] [blame] | 188 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 189 | } |
| 190 | |
Jan Scheffler | 085122e | 2021-08-07 08:04:40 | [diff] [blame] | 191 | private onError(event: Event): void { |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 192 | const eventTarget = (event.target as FileReader); |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 193 | this.#errorInternal = eventTarget.error; |
| 194 | this.#transferFinished(false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | } |
Tim van der Lippe | 0723204 | 2019-10-08 15:58:07 | [diff] [blame] | 196 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 197 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 198 | export class FileOutputStream implements Common.StringOutputStream.OutputStream { |
Benedikt Meurer | 84b0fcc | 2025-02-12 13:57:23 | [diff] [blame] | 199 | #writeCallbacks: Array<() => void>; |
Kateryna Prokopenko | 380fdfa | 2022-03-16 16:39:32 | [diff] [blame] | 200 | #fileName!: Platform.DevToolsPath.RawPathString|Platform.DevToolsPath.UrlString; |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 201 | #closed?: boolean; |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 202 | constructor() { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 203 | this.#writeCallbacks = []; |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 204 | } |
| 205 | |
Kateryna Prokopenko | 380fdfa | 2022-03-16 16:39:32 | [diff] [blame] | 206 | async open(fileName: Platform.DevToolsPath.RawPathString|Platform.DevToolsPath.UrlString): Promise<boolean> { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 207 | this.#closed = false; |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 208 | this.#writeCallbacks = []; |
| 209 | this.#fileName = fileName; |
Benedikt Meurer | 0048894 | 2025-06-17 17:52:25 | [diff] [blame] | 210 | const saveResponse = await Workspace.FileManager.FileManager.instance().save( |
| 211 | this.#fileName, TextUtils.ContentData.EMPTY_TEXT_CONTENT_DATA, /* forceSaveAs=*/ true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 212 | if (saveResponse) { |
Tim van der Lippe | 696c926 | 2020-08-26 14:39:32 | [diff] [blame] | 213 | Workspace.FileManager.FileManager.instance().addEventListener( |
Benedikt Meurer | b328d47 | 2024-08-23 13:41:15 | [diff] [blame] | 214 | Workspace.FileManager.Events.APPENDED_TO_URL, this.onAppendDone, this); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 215 | } |
Tim van der Lippe | ba0e645 | 2021-01-07 13:46:34 | [diff] [blame] | 216 | return Boolean(saveResponse); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | } |
| 218 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 219 | write(data: string): Promise<void> { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 220 | return new Promise(resolve => { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 221 | this.#writeCallbacks.push(resolve); |
| 222 | Workspace.FileManager.FileManager.instance().append(this.#fileName, data); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 223 | }); |
| 224 | } |
| 225 | |
Jan Scheffler | 2c9d5c3 | 2021-02-26 16:51:56 | [diff] [blame] | 226 | async close(): Promise<void> { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 227 | this.#closed = true; |
| 228 | if (this.#writeCallbacks.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 229 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 230 | } |
Tim van der Lippe | 696c926 | 2020-08-26 14:39:32 | [diff] [blame] | 231 | Workspace.FileManager.FileManager.instance().removeEventListener( |
Benedikt Meurer | b328d47 | 2024-08-23 13:41:15 | [diff] [blame] | 232 | Workspace.FileManager.Events.APPENDED_TO_URL, this.onAppendDone, this); |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 233 | Workspace.FileManager.FileManager.instance().close(this.#fileName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 234 | } |
| 235 | |
Kateryna Prokopenko | 1547632 | 2021-08-09 13:15:18 | [diff] [blame] | 236 | private onAppendDone(event: Common.EventTarget.EventTargetEvent<string>): void { |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 237 | if (event.data !== this.#fileName) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 238 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 239 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 240 | const writeCallback = this.#writeCallbacks.shift(); |
Tim van der Lippe | d0bc66a | 2020-08-26 15:02:14 | [diff] [blame] | 241 | if (writeCallback) { |
| 242 | writeCallback(); |
| 243 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 244 | if (this.#writeCallbacks.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 245 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 246 | } |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 247 | if (!this.#closed) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 249 | } |
Tim van der Lippe | 696c926 | 2020-08-26 14:39:32 | [diff] [blame] | 250 | Workspace.FileManager.FileManager.instance().removeEventListener( |
Benedikt Meurer | b328d47 | 2024-08-23 13:41:15 | [diff] [blame] | 251 | Workspace.FileManager.Events.APPENDED_TO_URL, this.onAppendDone, this); |
Tim van der Lippe | 113abec | 2021-10-12 11:30:36 | [diff] [blame] | 252 | Workspace.FileManager.FileManager.instance().close(this.#fileName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 253 | } |
Tim van der Lippe | 0723204 | 2019-10-08 15:58:07 | [diff] [blame] | 254 | } |