@vyr/service-asset 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyr/service-asset",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -8,6 +8,22 @@ import { AssetMethodProvider } from "./AssetMethodProvider"
8
8
 
9
9
  class AssetService extends Service {
10
10
  static key = 'asset'
11
+
12
+ static save = (name: string, data: string | Blob) => {
13
+ const blob = data instanceof Blob ? data : new Blob([data])
14
+ const url = window.URL.createObjectURL(blob)
15
+ const link = document.createElement('a')
16
+ link.href = url
17
+
18
+ link.setAttribute('download', name)
19
+ document.body.appendChild(link)
20
+ link.click()
21
+
22
+ // 清理
23
+ document.body.removeChild(link)
24
+ window.URL.revokeObjectURL(url)
25
+ }
26
+
11
27
  private _provider = new AssetMethodProvider(this)
12
28
  readonly root
13
29