Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Replace Buffer with TextEncoder/TextDecoder for mobile comptability #94

Closed
Closed
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: 9 additions & 2 deletions src/IcalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,17 @@ export class IcalService {
calendar = calendar.replace('~(*BSR_ANYCRLF)\R~', '\r\n');

// Line length should not be longer than 75 characters (https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html)
//#TODO I can't be bothered implementing this *should* requirement
//#TODO I can't be bothered implementing this *should* requirement

// Buffer is not used here because it relies on Node.js-specific APIs like Buffer.from and Buffer.toString,
// which are not available in environments like mobile versions of Obsidian.
// Instead, TextEncoder and TextDecoder are used for compatibility.

// Ensure we are UTF-8
calendar = Buffer.from(calendar, 'utf8').toString('utf8');
const encoder = new TextEncoder();
const decoder = new TextDecoder('utf-8');
const encoded = encoder.encode(calendar);
calendar = decoder.decode(encoded);

return calendar;
}
Expand Down