streams

javascript
const { Worker, MessageChannel } = require('node:worker_threads');
const path = require('node:path');

class WorkerPool {
  constructor(size) {
    this.workers = [];

Fan Out CPU Work to Node.js worker_threads and Merge Results via MessageChannel

nodejs worker-threads concurrency
by codesnips 3 tabs
javascript
const { Pool } = require('pg');
const Cursor = require('pg-cursor');

const pool = new Pool();

async function* streamUsers({ since, batchSize = 500 }) {

Stream a Large JSON Array Response in Node.js Without Buffering

nodejs streams transform-stream
by codesnips 3 tabs
typescript
import { Writable } from "node:stream";
import type { Pool } from "pg";

interface Row {
  email: string;
  name: string;

Streaming CSV import (Node streams)

streams postgres nodejs
by codesnips 3 tabs
javascript
const sharp = require('sharp');

const DEFAULTS = {
  maxWidth: 1600,
  maxHeight: 1600,
  format: 'webp',

Resize and Compress Uploaded Images with Sharp Before Saving to Disk

nodejs express sharp
by codesnips 3 tabs
typescript
import sharp from 'sharp';

export interface Variant {
  name: string;
  width: number;
  quality: number;

Generate WebP Image Thumbnails on Upload with Sharp and Express

express sharp image-processing
by codesnips 3 tabs
rust
use std::collections::HashSet;
use std::hash::Hash;

pub struct DedupByKey<I, K, F> {
    inner: I,
    key_fn: F,

Order-Preserving Stream Deduplication by Key in Rust with a HashSet Guard

rust streams deduplication
by codesnips 3 tabs
java
package com.example.paging;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

Consume a Paginated REST API by Following Next-Page Links in Java

java pagination rest-api
by codesnips 3 tabs
javascript
'use strict';

const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const crypto = require('crypto');

Stream a Multipart Upload Through Gzip to Disk with stream.pipeline

nodejs streams backpressure
by codesnips 2 tabs
javascript
'use strict';

const { Transform } = require('stream');

class LineSplitter extends Transform {
  constructor(options = {}) {

Split a Large Log File Into Date-Based Chunks With a Node.js Transform Stream

nodejs streams backpressure
by codesnips 3 tabs
java
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

import Transaction.Category;

Grouping and Summarizing Transactions with Java Stream Collectors

java streams collectors
by codesnips 3 tabs
javascript
const multer = require('multer');

const ALLOWED_MIME = new Set(['image/jpeg', 'image/png', 'image/webp']);

function fileFilter(req, file, cb) {
  if (!ALLOWED_MIME.has(file.mimetype)) {

Upload and Resize User Avatars with Multer and Sharp in Express

express multer sharp
by codesnips 3 tabs
javascript
const express = require('express');
const multer = require('multer');
const os = require('os');
const fs = require('fs/promises');
const { parseCsvStream } = require('./csvStreamParser');

Stream and Validate Large CSV Uploads Row-by-Row with Node Streams and Backpressure

nodejs streams csv
by codesnips 3 tabs