يوفر Bun عددًا من دوال الراحة لقراءة محتويات ReadableStream بتنسيقات مختلفة. كتلة الكود هذه تقرأ محتويات ReadableStream إلى ArrayBuffer، ثم تنشئ Uint8Array تشير إلى المخزن المؤقت.
ts
const stream = new ReadableStream();
const buf = await Bun.readableStreamToArrayBuffer(stream);
const uint8 = new Uint8Array(buf);بالإضافة إلى ذلك، توجد دالة راحة للتحويل مباشرة إلى Uint8Array.
ts
const stream = new ReadableStream();
const uint8 = await Bun.readableStreamToBytes(stream);راجع الوثائق > API > أدوات مساعدة للحصول على وثائق دوال تحويل ReadableStream الأخرى في Bun.