Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
ReadDirItem,
StatResult,
DownloadFileOptions,
DownloadResult,
DownloadFileResult,
Encoding,
EncodingOrOptions,
ProcessedOptions,
Expand Down Expand Up @@ -52,7 +52,7 @@ function parseOptions(encodingOrOptions?: EncodingOrOptions): ProcessedOptions {
return options;
}

function encodeContents(contents: string, encoding: Encoding) {
function encodeContents(contents: string, encoding: Encoding): string {
if (encoding === 'utf8') {
return btoa(encode_utf8(contents));
}
Expand All @@ -68,7 +68,7 @@ function encodeContents(contents: string, encoding: Encoding) {
throw new Error('Invalid encoding type "' + String(encoding) + '"');
}

function decodeContents(b64: string, encoding: Encoding) {
function decodeContents(b64: string, encoding: Encoding): string {
if (encoding === 'utf8') {
return atob(decode_utf8(b64));
}
Expand Down Expand Up @@ -208,10 +208,7 @@ export default {
return RNFSManager.write(normalizeFilePath(filepath), b64, position).then(() => void 0);
},

downloadFile(options: DownloadFileOptions): {
jobId: number;
promise: Promise<DownloadResult>;
} {
downloadFile(options: DownloadFileOptions): DownloadFileResult {
const jobId = getJobId();
let subscriptions: EmitterSubscription[] = [];

Expand Down
11 changes: 8 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,29 @@ export type DownloadFileOptions = {
};

export type DownloadBeginCallbackResult = {
jobId: number; // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
jobId: number; // The download jobId, required if one wishes to cancel the download. See `stopDownload`.
statusCode: number; // The HTTP status code
contentLength: number; // The total size in bytes of the download resource
headers: Headers; // The HTTP response headers from the server
};

export type DownloadProgressCallbackResult = {
jobId: number; // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
jobId: number; // The download jobId, required if one wishes to cancel the download. See `stopDownload`.
contentLength: number; // The total size in bytes of the download resource
bytesWritten: number; // The number of bytes written to the file so far
};

export type DownloadResult = {
jobId: number; // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
jobId: number; // The download jobId, required if one wishes to cancel the download. See `stopDownload`.
statusCode: number; // The HTTP status code
bytesWritten: number; // The number of bytes written to the file
};

export type DownloadFileResult = {
jobId: number;
promise: Promise<DownloadResult>;
};

export type FSInfoResult = {
totalSpace: number; // The total amount of storage space on the device (in bytes).
freeSpace: number; // The amount of available storage space on the device (in bytes).
Expand Down