Skip to content

Commit

Permalink
refactor: adjust tests for splitMultipart
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordfirespeed committed Aug 20, 2024
1 parent 4455424 commit 3f506d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/utils/split-multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export function splitMultipart(toSplit: Buffer, boundary: Buffer): Buffer[]
export function splitMultipart(toSplit: Buffer, boundary: string, encoding?: BufferEncoding): Buffer[]
export function splitMultipart(toSplit: Buffer, boundary: string | Buffer, encoding?: BufferEncoding): Buffer[] {
const parts: Buffer[] = []
if (!(boundary instanceof Buffer)) {
boundary = Buffer.from(`\r\n--${boundary}`, encoding)
}
boundary = Buffer.from(`\r\n--${boundary}`, encoding)

let currentIndex = 0
let previousPartBeginIndex = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect, it } from 'vitest'

import { splitBuffer } from '@/utils/split-buffer'
import { splitMultipart } from '@/utils/split-multipart'

it('should split correctly with string delimiter', () => {
const toSplit = Buffer.from('abc foo bar foo baz foo quux foo \n')
expect(splitBuffer(toSplit, ' foo ', 'utf-8')).toEqual([
const toSplit = Buffer.from('abc\r\n--foo\r\nbar\r\n--foo\r\nbaz\r\n--foo\r\nquux\r\n--foo--\r\n\n')
expect(splitMultipart(toSplit, 'foo', 'utf-8')).toEqual([
Buffer.from('abc'),
Buffer.from('bar'),
Buffer.from('baz'),
Expand All @@ -14,8 +14,8 @@ it('should split correctly with string delimiter', () => {
})

it('should split correctly with buffer delimiter', () => {
const toSplit = Buffer.from('abc foo bar foo baz foo quux foo \n')
expect(splitBuffer(toSplit, Buffer.from(' foo '))).toEqual([
const toSplit = Buffer.from('abc\r\n--foo\r\nbar\r\n--foo\r\nbaz\r\n--foo\r\nquux\r\n--foo--\r\n\n')
expect(splitMultipart(toSplit, Buffer.from('foo'))).toEqual([
Buffer.from('abc'),
Buffer.from('bar'),
Buffer.from('baz'),
Expand Down

0 comments on commit 3f506d8

Please sign in to comment.