Skip to content

Commit

Permalink
drop unnecesary dependecy
Browse files Browse the repository at this point in the history
fix typo
  • Loading branch information
agh92 committed May 30, 2021
1 parent faace43 commit fbe3ceb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The project was created with the angular cli and it's based on electron.

## Run

Run `npm run buld:start:electron` to run a dev build of the application.
Run `npm run build:start:electron` to run a dev build of the application.

## Build

Expand Down
33 changes: 3 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"release:electron": "npm run clean:release && npm run build:electron && npm run pack:electron",
"pack:electron": "cp -r ./node_modules ./dist && cd dist && electron-packager . ogg-explorer --out ./../release",
"clean:dist": "rm -f -r ./dist",
"clean:release": "rm -f -r ./release",
"install:ogg": "npm i git://github.com/agh92/node-ogg.git#develop && electron-rebuild"
"clean:release": "rm -f -r ./release"
},
"private": true,
"dependencies": {
Expand All @@ -30,7 +29,6 @@
"@angular/platform-browser-dynamic": "~12.0.0",
"@angular/router": "~12.0.0",
"electron-default-menu": "^1.0.2",
"ogg": "git://github.com/agh92/node-ogg.git#develop",
"rxjs": "^6.6.7",
"sound-play": "^1.1.0",
"tslib": "^2.1.0",
Expand Down
8 changes: 4 additions & 4 deletions projects/main/src/providers/voice-notes.provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ describe('VoiceNotesProvider', () => {

let voiceNotesProvider: VoiceNotesProvider;
let mockReadContetnsOfDir: SinonStub;
let mockCountOggPackets: SinonStub;
let mockGetSizeInBytes: SinonStub;
let mockFiles: string[];

beforeEach(() => {
voiceNotesProvider = new VoiceNotesProvider();
mockReadContetnsOfDir = ImportMock.mockFunction(fileUtils, 'readContentsOfDir');
mockCountOggPackets = ImportMock.mockFunction(fileUtils, 'countOggPackets');
mockCountOggPackets.resolves(0);
mockGetSizeInBytes = ImportMock.mockFunction(fileUtils, 'getSizeInBytes');
mockGetSizeInBytes.returns(0);
});

afterEach(() => {
mockFiles = [];
mockReadContetnsOfDir.restore();
mockCountOggPackets.restore();
mockGetSizeInBytes.restore();
});

describe('getVoiceNotes', () => {
Expand Down
2 changes: 1 addition & 1 deletion projects/main/src/providers/voice-notes.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class VoiceNotesProvider {
location,
type: 'audio/ogg',
name: file,
length: await fileUtils.countOggPackets(location)
length: fileUtils.getSizeInBytes(location)
} as VoiceNote
});
return Promise.all(returnValue);
Expand Down
26 changes: 3 additions & 23 deletions projects/main/src/utils/file.utils.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
import { Readable, Writable } from "stream";
import fs from 'fs';

const ogg = require('ogg');
const sound = require("sound-play");

export function countOggPackets(file: string): Promise<number> {
const decoder: Writable = new ogg.Decoder();
const readStream: Readable = fs.createReadStream(file);

let numberOfPackets = 0;

decoder.on('stream', (stream: Readable) => {
stream.on('data', () => numberOfPackets++);
});

return new Promise(resolve => {
decoder.on('finish', () => {
console.log(`finish ${file}`);
readStream.unpipe(decoder);
decoder.end();
resolve(numberOfPackets);
});

// pipe the ogg file to the Decoder
readStream.pipe(decoder);
});
export function getSizeInBytes(file: string): number {
const stats = fs.statSync(file)
return stats.size;
}

export async function playAudioFile(file: string) {
Expand Down

0 comments on commit fbe3ceb

Please sign in to comment.