MCPcopy
hub / github.com/jvilk/BrowserFS / sync

Method sync

src/backend/HTML5FS.ts:117–138  ·  view source on GitHub ↗
(cb: BFSOneArgCallback)

Source from the content-addressed store, hash-verified

115 }
116
117 public sync(cb: BFSOneArgCallback): void {
118 if (!this.isDirty()) {
119 return cb();
120 }
121
122 this._entry.createWriter((writer) => {
123 const buffer = this.getBuffer();
124 const blob = new Blob([buffer2ArrayBuffer(buffer)]);
125 const length = blob.size;
126 writer.onwriteend = (err?: any) => {
127 writer.onwriteend = <any> null;
128 writer.onerror = <any> null;
129 writer.truncate(length);
130 this.resetDirty();
131 cb();
132 };
133 writer.onerror = (err: any) => {
134 cb(convertError(err, this.getPath(), false));
135 };
136 writer.write(blob);
137 });
138 }
139
140 public close(cb: BFSOneArgCallback): void {
141 this.sync(cb);

Callers 1

closeMethod · 0.95

Calls 9

buffer2ArrayBufferFunction · 0.90
cbFunction · 0.85
isDirtyMethod · 0.80
getBufferMethod · 0.80
resetDirtyMethod · 0.80
getPathMethod · 0.80
convertErrorFunction · 0.70
truncateMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected