mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 23:53:48 +01:00
65cd14e33b
* Add specific types for sleeve tasks * Moved LocationName enum to overall enums file * Add LocationName enum to those provided to player * remove trailing s on CompanyPosNames enum (now CompanyPosName, in line with LocationName) * Also regenerated all ns documentation. This leads to an expected error when checking for generated files, because PRs should not normally touch markdown files. Also leads to a lint failure in generated file bitburner.d.ts * also removed some exporting from NetscriptDefinitions.d.ts for anything that wasn't imported somewhere else.
55 lines
2.1 KiB
Markdown
55 lines
2.1 KiB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [wget](./bitburner.ns.wget.md)
|
||
|
||
## NS.wget() method
|
||
|
||
Download a file from the internet.
|
||
|
||
<b>Signature:</b>
|
||
|
||
```typescript
|
||
wget(url: string, target: string, host?: string): Promise<boolean>;
|
||
```
|
||
|
||
## Parameters
|
||
|
||
| Parameter | Type | Description |
|
||
| --- | --- | --- |
|
||
| url | string | URL to pull data from. |
|
||
| target | string | Filename to write data to. Must be script or text file. |
|
||
| host | string | Optional hostname/ip of server for target file. |
|
||
|
||
<b>Returns:</b>
|
||
|
||
Promise<boolean>
|
||
|
||
True if the data was successfully retrieved from the URL, false otherwise.
|
||
|
||
## Remarks
|
||
|
||
RAM cost: 0 GB
|
||
|
||
Retrieves data from a URL and downloads it to a file on the specified server. The data can only be downloaded to a script (.script, .js) or a text file (.txt). If the file already exists, it will be overwritten by this command. Note that it will not be possible to download data from many websites because they do not allow cross-origin resource sharing (CORS).
|
||
|
||
IMPORTANT: This is an asynchronous function that returns a Promise. The Promise’s resolved value will be a boolean indicating whether or not the data was successfully retrieved from the URL. Because the function is async and returns a Promise, it is recommended you use wget in NetscriptJS (Netscript 2.0).
|
||
|
||
In NetscriptJS, you must preface any call to wget with the await keyword (like you would [hack](./bitburner.ns.hack.md) or [sleep](./bitburner.ns.sleep.md)<!-- -->). wget will still work in Netscript 1.0, but the function's execution will not be synchronous (i.e. it may not execute when you expect/want it to). Furthermore, since Promises are not supported in ES5, you will not be able to process the returned value of wget in Netscript 1.0.
|
||
|
||
## Example 1
|
||
|
||
|
||
```ts
|
||
// NS1:
|
||
wget("https://raw.githubusercontent.com/bitburner-official/bitburner-src/master/README.md", "game_readme.txt");
|
||
```
|
||
|
||
## Example 2
|
||
|
||
|
||
```ts
|
||
// NS2:
|
||
await ns.wget("https://raw.githubusercontent.com/bitburner-official/bitburner-src/master/README.md", "game_readme.txt");
|
||
```
|
||
|