@theia/ffmpeg 1.53.0-next.5 → 1.53.0-next.55

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/src/index.ts CHANGED
@@ -1,20 +1,20 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- export * from './hash';
18
- export * from './ffmpeg';
19
- export * from './check-ffmpeg';
20
- export * from './replace-ffmpeg';
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ export * from './hash';
18
+ export * from './ffmpeg';
19
+ export * from './check-ffmpeg';
20
+ export * from './replace-ffmpeg';
@@ -1,80 +1,80 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import electronGet = require('@electron/get');
18
- import fs = require('fs-extra');
19
- import os = require('os');
20
- import path = require('path');
21
- import unzipper = require('unzipper');
22
- import * as ffmpeg from './ffmpeg';
23
- import { hashFile } from './hash';
24
-
25
- export async function replaceFfmpeg(options: ffmpeg.FfmpegOptions = {}): Promise<void> {
26
- let shouldDownload = true;
27
- let shouldReplace = true;
28
- const {
29
- name: ffmpegName,
30
- location: ffmpegLocation,
31
- } = ffmpeg.ffmpegNameAndLocation(options);
32
- const {
33
- electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist'),
34
- electronVersion = await readElectronVersion(electronDist),
35
- ffmpegPath = path.resolve(electronDist, ffmpegLocation, ffmpegName),
36
- } = options;
37
- const ffmpegCachedPath = path.join(os.tmpdir(), `theia-cli/cache/electron-v${electronVersion}`, ffmpegName);
38
- if (await fs.pathExists(ffmpegCachedPath)) {
39
- shouldDownload = false; // If the file is already cached, do not download.
40
- console.warn('Found cached ffmpeg library.');
41
- const [cacheHash, distHash] = await Promise.all([
42
- hashFile(ffmpegCachedPath),
43
- hashFile(ffmpegPath),
44
- ]);
45
- if (cacheHash.equals(distHash)) {
46
- shouldReplace = false; // If files are already the same, do not replace.
47
- console.warn('Hashes are equal, not replacing the ffmpeg library.');
48
- }
49
- }
50
- if (shouldDownload) {
51
- const ffmpegZipPath = await electronGet.downloadArtifact({
52
- version: electronVersion,
53
- artifactName: 'ffmpeg'
54
- });
55
- const ffmpegZip = await unzipper.Open.file(ffmpegZipPath);
56
- const file = ffmpegZip.files.find(f => f.path.endsWith(ffmpegName));
57
- if (!file) {
58
- throw new Error(`Archive did not contain "${ffmpegName}".`);
59
- }
60
- // Extract file to cache.
61
- await fs.mkdirp(path.dirname(ffmpegCachedPath));
62
- await new Promise((resolve, reject) => {
63
- file.stream()
64
- .pipe(fs.createWriteStream(ffmpegCachedPath))
65
- .on('finish', resolve)
66
- .on('error', reject);
67
- });
68
- console.warn(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
69
- }
70
- if (shouldReplace) {
71
- await fs.copy(ffmpegCachedPath, ffmpegPath);
72
- console.warn(`Successfully replaced "${ffmpegPath}".`);
73
- }
74
- }
75
-
76
- export async function readElectronVersion(electronDist: string): Promise<string> {
77
- const electronVersionFilePath = path.resolve(electronDist, 'version');
78
- const version = await fs.readFile(electronVersionFilePath, 'utf8');
79
- return version.trim();
80
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import electronGet = require('@electron/get');
18
+ import fs = require('fs-extra');
19
+ import os = require('os');
20
+ import path = require('path');
21
+ import unzipper = require('unzipper');
22
+ import * as ffmpeg from './ffmpeg';
23
+ import { hashFile } from './hash';
24
+
25
+ export async function replaceFfmpeg(options: ffmpeg.FfmpegOptions = {}): Promise<void> {
26
+ let shouldDownload = true;
27
+ let shouldReplace = true;
28
+ const {
29
+ name: ffmpegName,
30
+ location: ffmpegLocation,
31
+ } = ffmpeg.ffmpegNameAndLocation(options);
32
+ const {
33
+ electronDist = path.resolve(require.resolve('electron/package.json'), '..', 'dist'),
34
+ electronVersion = await readElectronVersion(electronDist),
35
+ ffmpegPath = path.resolve(electronDist, ffmpegLocation, ffmpegName),
36
+ } = options;
37
+ const ffmpegCachedPath = path.join(os.tmpdir(), `theia-cli/cache/electron-v${electronVersion}`, ffmpegName);
38
+ if (await fs.pathExists(ffmpegCachedPath)) {
39
+ shouldDownload = false; // If the file is already cached, do not download.
40
+ console.warn('Found cached ffmpeg library.');
41
+ const [cacheHash, distHash] = await Promise.all([
42
+ hashFile(ffmpegCachedPath),
43
+ hashFile(ffmpegPath),
44
+ ]);
45
+ if (cacheHash.equals(distHash)) {
46
+ shouldReplace = false; // If files are already the same, do not replace.
47
+ console.warn('Hashes are equal, not replacing the ffmpeg library.');
48
+ }
49
+ }
50
+ if (shouldDownload) {
51
+ const ffmpegZipPath = await electronGet.downloadArtifact({
52
+ version: electronVersion,
53
+ artifactName: 'ffmpeg'
54
+ });
55
+ const ffmpegZip = await unzipper.Open.file(ffmpegZipPath);
56
+ const file = ffmpegZip.files.find(f => f.path.endsWith(ffmpegName));
57
+ if (!file) {
58
+ throw new Error(`Archive did not contain "${ffmpegName}".`);
59
+ }
60
+ // Extract file to cache.
61
+ await fs.mkdirp(path.dirname(ffmpegCachedPath));
62
+ await new Promise((resolve, reject) => {
63
+ file.stream()
64
+ .pipe(fs.createWriteStream(ffmpegCachedPath))
65
+ .on('finish', resolve)
66
+ .on('error', reject);
67
+ });
68
+ console.warn(`Downloaded ffmpeg shared library { version: "${electronVersion}", dist: "${electronDist}" }.`);
69
+ }
70
+ if (shouldReplace) {
71
+ await fs.copy(ffmpegCachedPath, ffmpegPath);
72
+ console.warn(`Successfully replaced "${ffmpegPath}".`);
73
+ }
74
+ }
75
+
76
+ export async function readElectronVersion(electronDist: string): Promise<string> {
77
+ const electronVersionFilePath = path.resolve(electronDist, 'version');
78
+ const version = await fs.readFile(electronVersionFilePath, 'utf8');
79
+ return version.trim();
80
+ }