MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / toFile

Function toFile

packages/core/http/http-request/index.android.ts:39–60  ·  view source on GitHub ↗
(this: BaseHttpContent, destinationFilePath: string)

Source from the content-addressed store, hash-verified

37 return this.toNativeImage().then((value) => new ImageSource(value));
38 },
39 toFile(this: BaseHttpContent, destinationFilePath: string) {
40 if (!destinationFilePath) {
41 destinationFilePath = getFilenameFromUrl(this.requestURL);
42 }
43 let stream: java.io.FileOutputStream;
44 try {
45 // ensure destination path exists by creating any missing parent directories
46 const file = File.fromPath(destinationFilePath);
47
48 const javaFile = new java.io.File(destinationFilePath);
49 stream = new java.io.FileOutputStream(javaFile);
50 stream.write((this.raw as java.io.ByteArrayOutputStream).toByteArray());
51
52 return file;
53 } catch (exception) {
54 throw new Error(`Cannot save file with path: ${destinationFilePath}.`);
55 } finally {
56 if (stream) {
57 stream.close();
58 }
59 }
60 },
61};
62
63export function request(options: HttpRequestOptions): Promise<HttpResponse> {

Callers

nothing calls this directly

Calls 4

getFilenameFromUrlFunction · 0.90
writeMethod · 0.65
fromPathMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected